From 689bbfdc45f6f85be4008efa0ea58fa781b178f0 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 28 Jul 2009 10:15:09 +0200 Subject: [PATCH] Rename all structure definitions in the "typedef struct _SomeStruct" format to "typedef struct SomeStruct_" to make the Doxygen output more useful. Remove the Trie multi pattern matcher code. It wasn't used anymore. --- src/Makefile.am | 1 - src/alert-debuglog.c | 2 +- src/alert-fastlog.c | 2 +- src/alert-unified-alert.c | 6 +- src/alert-unified-log.c | 6 +- src/decode-ethernet.h | 2 +- src/decode-icmpv4.h | 2 +- src/decode-icmpv6.h | 2 +- src/decode-ipv4.h | 12 +- src/decode-ipv6.h | 30 +- src/decode-ppp.h | 70 +- src/decode-tcp.h | 6 +- src/decode-udp.h | 4 +- src/decode.h | 24 +- src/detect-content.h | 2 +- src/detect-dsize.h | 2 +- src/detect-engine-mpm.c | 2 +- src/detect-flow.h | 2 +- src/detect-flowbits.h | 2 +- src/detect-flowvar.h | 2 +- src/detect-pcre.h | 2 +- src/detect-pktvar.h | 2 +- src/detect-uricontent.h | 2 +- src/detect.h | 38 +- src/flow-bit.h | 2 +- src/flow-hash.h | 2 +- src/flow-queue.h | 2 +- src/flow-var.h | 2 +- src/flow.h | 16 +- src/host.h | 4 +- src/l7-app-detect.c | 2 +- src/log-httplog.c | 2 +- src/packet-queue.h | 2 +- src/respond-reject-libnet11.c | 2 +- src/source-nfq.h | 6 +- src/source-pcap.h | 2 +- src/stream-tcp-private.h | 10 +- src/stream-tcp.c | 2 +- src/stream.h | 8 +- src/threadvars.h | 10 +- src/tm-modules.h | 2 +- src/tm-queuehandlers.h | 2 +- src/tm-queues.h | 2 +- src/tm-threads.c | 12 +- src/util-bloomfilter-counting.h | 2 +- src/util-bloomfilter.h | 2 +- src/util-hash.c | 2 +- src/util-hash.h | 10 +- src/util-hashlist.c | 2 +- src/util-hashlist.h | 14 +- src/util-mpm-b2g.h | 18 +- src/util-mpm-b3g.h | 20 +- src/util-mpm-trie.c | 1426 ------------------------------- src/util-mpm-trie.h | 86 -- src/util-mpm-wumanber.h | 16 +- src/util-mpm.c | 2 - src/util-mpm.h | 79 +- src/util-pool.h | 6 +- src/util-unittest.c | 6 +- src/util-unittest.h | 8 +- src/util-var-name.c | 2 +- src/util-var.h | 4 +- 62 files changed, 256 insertions(+), 1766 deletions(-) delete mode 100644 src/util-mpm-trie.c delete mode 100644 src/util-mpm-trie.h diff --git a/src/Makefile.am b/src/Makefile.am index 0807e15d0f..8adbfaff2d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -60,7 +60,6 @@ detect-flow.c detect-flow.h \ detect-dsize.c detect-dsize.h \ detect-noalert.c detect-noalert.h \ util-print.c util-print.h \ -util-mpm-trie.c util-mpm-trie.h \ util-mpm.c util-mpm.h \ util-binsearch.c util-binsearch.h \ util-mpm-wumanber.c util-mpm-wumanber.h \ diff --git a/src/alert-debuglog.c b/src/alert-debuglog.c index 1bd59535a6..dbef473a48 100644 --- a/src/alert-debuglog.c +++ b/src/alert-debuglog.c @@ -65,7 +65,7 @@ void TmModuleAlertDebuglogIPv6Register (void) { tmm_modules[TMM_ALERTDEBUGLOG6].RegisterTests = NULL; } */ -typedef struct _AlertDebuglogThread { +typedef struct AlertDebuglogThread_ { FILE *fp; u_int32_t alerts; } AlertDebuglogThread; diff --git a/src/alert-fastlog.c b/src/alert-fastlog.c index 7a0c5b41d0..acdd9d65aa 100644 --- a/src/alert-fastlog.c +++ b/src/alert-fastlog.c @@ -65,7 +65,7 @@ void TmModuleAlertFastlogIPv6Register (void) { tmm_modules[TMM_ALERTFASTLOG6].RegisterTests = NULL; } -typedef struct _AlertFastlogThread { +typedef struct AlertFastlogThread_ { FILE *fp; u_int32_t alerts; } AlertFastlogThread; diff --git a/src/alert-unified-alert.c b/src/alert-unified-alert.c index bd78931cbb..5c2669dc31 100644 --- a/src/alert-unified-alert.c +++ b/src/alert-unified-alert.c @@ -45,7 +45,7 @@ void TmModuleAlertUnifiedAlertRegister (void) { tmm_modules[TMM_ALERTUNIFIEDALERT].RegisterTests = NULL; } -typedef struct _AlertUnifiedAlertThread { +typedef struct AlertUnifiedAlertThread_ { FILE *fp; u_int32_t size_limit; u_int32_t size_current; @@ -55,14 +55,14 @@ typedef struct _AlertUnifiedAlertThread { #define ALERTUNIFIEDALERT_VERMAJOR 1 /* taken from Snort */ #define ALERTUNIFIEDALERT_VERMINOR 81 /* taken from Snort */ -typedef struct _AlertUnifiedAlertFileHeader { +typedef struct AlertUnifiedAlertFileHeader_ { u_int32_t magic; u_int32_t ver_major; u_int32_t ver_minor; u_int32_t timezone; } AlertUnifiedAlertFileHeader; -typedef struct _AlertUnifiedAlertPacketHeader { +typedef struct AlertUnifiedAlertPacketHeader_ { /* Snort's 'Event' structure */ u_int32_t sig_gen; u_int32_t sig_sid; diff --git a/src/alert-unified-log.c b/src/alert-unified-log.c index 932d7804ff..d4f9d59293 100644 --- a/src/alert-unified-log.c +++ b/src/alert-unified-log.c @@ -45,7 +45,7 @@ void TmModuleAlertUnifiedLogRegister (void) { tmm_modules[TMM_ALERTUNIFIEDLOG].RegisterTests = NULL; } -typedef struct _AlertUnifiedLogThread { +typedef struct AlertUnifiedLogThread_ { FILE *fp; u_int32_t size_limit; u_int32_t size_current; @@ -55,7 +55,7 @@ typedef struct _AlertUnifiedLogThread { #define ALERTUNIFIEDLOG_VERMAJOR 1 /* taken from Snort */ #define ALERTUNIFIEDLOG_VERMINOR 2 /* taken from Snort */ -typedef struct _AlertUnifiedLogFileHeader { +typedef struct AlertUnifiedLogFileHeader_ { u_int32_t magic; u_int16_t ver_major; u_int16_t ver_minor; @@ -65,7 +65,7 @@ typedef struct _AlertUnifiedLogFileHeader { u_int32_t linktype; } AlertUnifiedLogFileHeader; -typedef struct _AlertUnifiedLogPacketHeader { +typedef struct AlertUnifiedLogPacketHeader_ { /* Snort's 'Event' structure */ u_int32_t sig_gen; u_int32_t sig_sid; diff --git a/src/decode-ethernet.h b/src/decode-ethernet.h index 8eb054f1f6..76e0bae1f3 100644 --- a/src/decode-ethernet.h +++ b/src/decode-ethernet.h @@ -17,7 +17,7 @@ #define ETHERNET_TYPE_8021Q 0x8100 #define ETHERNET_TYPE_LOOP 0x9000 -typedef struct _EthernetHdr { +typedef struct EthernetHdr_ { u_int8_t eth_dst[6]; u_int8_t eth_src[6]; u_int16_t eth_type; diff --git a/src/decode-icmpv4.h b/src/decode-icmpv4.h index 0f77645ffa..3c993539d4 100644 --- a/src/decode-icmpv4.h +++ b/src/decode-icmpv4.h @@ -124,7 +124,7 @@ #endif /* ICMPv4 header structure */ -typedef struct _ICMPV4Hdr +typedef struct ICMPV4Hdr_ { u_int8_t type; u_int8_t code; diff --git a/src/decode-icmpv6.h b/src/decode-icmpv6.h index befc787ac5..716f2a1290 100644 --- a/src/decode-icmpv6.h +++ b/src/decode-icmpv6.h @@ -64,7 +64,7 @@ #endif -typedef struct _ICMPV6Hdr +typedef struct ICMPV6Hdr_ { u_int8_t type; u_int8_t code; diff --git a/src/decode-ipv4.h b/src/decode-ipv4.h index d767174d00..f0c1839654 100644 --- a/src/decode-ipv4.h +++ b/src/decode-ipv4.h @@ -21,7 +21,7 @@ #define IPV4_OPT_SECURITY 0x82 #define IPV4_OPT_LSRR 0x83 -typedef struct _IPV4Hdr +typedef struct IPV4Hdr_ { u_int8_t ip_verhl; /* version & header length */ u_int8_t ip_tos; @@ -113,8 +113,12 @@ typedef struct _IPV4Hdr #define IPV4_CACHE_IPTTL 0x0400 /* 1024*/ #define IPV4_CACHE_IPPROTO 0x0800 /* 2048 */ -/* decoder cache */ -typedef struct _IPV4Cache +/** + * IPv4 decoder cache + * + * Used for storing parsed values. + */ +typedef struct IPV4Cache_ { u_int16_t flags; @@ -137,7 +141,7 @@ typedef struct _IPV4Cache } IPV4Cache; /* helper structure with parsed ipv4 info */ -typedef struct _IPV4Vars +typedef struct IPV4Vars_ { u_int8_t ip_opts_len; } IPV4Vars; diff --git a/src/decode-ipv6.h b/src/decode-ipv6.h index 653a26dd31..663478a207 100644 --- a/src/decode-ipv6.h +++ b/src/decode-ipv6.h @@ -13,10 +13,10 @@ #define IPV6_MAXPACKET 65535 /* maximum packet size */ #define IPV6_MAX_OPT 40 -typedef struct _IPV6Hdr +typedef struct IPV6Hdr_ { union { - struct _ip6_un1 { + struct ip6_un1_ { u_int32_t ip6_un1_flow; /* 20 bits of flow-ID */ u_int16_t ip6_un1_plen; /* payload length */ u_int8_t ip6_un1_nxt; /* next header */ @@ -83,7 +83,7 @@ typedef struct _IPV6Hdr #define IPV6_CACHE_HLIM 0x0020 /* 32 */ /* decoder cache */ -typedef struct _IPV6Cache +typedef struct IPV6Cache_ { u_int16_t flags; u_int8_t ver; @@ -95,7 +95,7 @@ typedef struct _IPV6Cache } IPV6Cache; /* helper structure with parsed ipv6 info */ -typedef struct _IPV6Vars +typedef struct IPV6Vars_ { u_int8_t ip_opts_len; u_int8_t l4proto; /* the proto after the extension headers @@ -104,7 +104,7 @@ typedef struct _IPV6Vars } IPV6Vars; /* Fragment header */ -typedef struct _IPV6FragHdr +typedef struct IPV6FragHdr_ { u_int8_t ip6fh_nxt; /* next header */ u_int8_t ip6fh_reserved; /* reserved field */ @@ -125,7 +125,7 @@ typedef struct _IPV6FragHdr #define IPV6_EXTHDR_GET_FH_ID(p) IPV6_EXTHDR_GET_RAW_FH_ID((p)) /* rfc 1826 */ -typedef struct _IPV6AuthHdr +typedef struct IPV6AuthHdr_ { u_int8_t ip6ah_nxt; /* next header */ u_int8_t ip6ah_len; /* header length in units of 8 bytes, not @@ -135,13 +135,13 @@ typedef struct _IPV6AuthHdr u_int32_t ip6ah_seq; /* sequence number */ } IPV6AuthHdr; -typedef struct _IPV6EspHdr +typedef struct IPV6EspHdr_ { u_int32_t ip6esph_spi; /* SECURITY PARAMETERS INDEX (SPI) */ u_int32_t ip6esph_seq; /* sequence number */ } IPV6EspHdr; -typedef struct _IPV6RouteHdr +typedef struct IPV6RouteHdr_ { u_int8_t ip6rh_nxt; /* next header */ u_int8_t ip6rh_len; /* header length in units of 8 bytes, not @@ -174,7 +174,7 @@ typedef struct _IPV6RouteHdr #define IPV6OPT_HAO 0xC9 /* Home Address Option */ -typedef struct _IPV6OptHAO +typedef struct IPV6OptHAO_ { u_int8_t ip6hao_type; /* Option type */ u_int8_t ip6hao_len; /* Option Data len (excludes type and len) */ @@ -182,7 +182,7 @@ typedef struct _IPV6OptHAO } IPV6OptHAO; /* Router Alert Option */ -typedef struct _IPV6OptRA +typedef struct IPV6OptRA_ { u_int8_t ip6ra_type; /* Option type */ u_int8_t ip6ra_len; /* Option Data len (excludes type and len) */ @@ -190,14 +190,14 @@ typedef struct _IPV6OptRA } IPV6OptRA; /* Jumbo Option */ -typedef struct _IPV6OptJumbo +typedef struct IPV6OptJumbo_ { u_int8_t ip6j_type; /* Option type */ u_int8_t ip6j_len; /* Option Data len (excludes type and len) */ u_int32_t ip6j_payload_len; /* Jumbo Payload Length */ } IPV6OptJumbo; -typedef struct _IPV6HopOptsHdr +typedef struct IPV6HopOptsHdr_ { u_int8_t ip6hh_nxt; /* next header */ u_int8_t ip6hh_len; /* header length in units of 8 bytes, not @@ -212,7 +212,7 @@ typedef struct _IPV6HopOptsHdr #define IPV6_EXTHDR_GET_HH_HDRLEN(p) IPV6_EXTHDR_GET_RAW_HH_HDRLEN((p)) /* XXX */ -typedef struct _IPV6DstOptsHdr +typedef struct IPV6DstOptsHdr_ { u_int8_t ip6dh_nxt; /* next header */ u_int8_t ip6dh_len; /* header length in units of 8 bytes, not @@ -235,7 +235,7 @@ typedef struct _IPV6DstOptsHdr #define IPV6_EXTHDR_GET_DH2_HDRLEN(p) IPV6_EXTHDR_GET_RAW_DH2_HDRLEN((p)) /* XXX */ -typedef struct _IPV6GenOptHdr +typedef struct IPV6GenOptHdr_ { u_int8_t type; u_int8_t next; @@ -243,7 +243,7 @@ typedef struct _IPV6GenOptHdr u_int8_t *data; } IPV6GenOptHdr; -typedef struct _IPV6ExtHdrs +typedef struct IPV6ExtHdrs_ { IPV6FragHdr *ip6fh; /* In fh_offset we store the offset of this extension into the packet past diff --git a/src/decode-ppp.h b/src/decode-ppp.h index 988ee9f784..2d57392395 100644 --- a/src/decode-ppp.h +++ b/src/decode-ppp.h @@ -6,49 +6,49 @@ /* Point to Point Protocol RFC1331 - Supported tyes */ -#define PPP_IP 0x0021 /* Internet Protocol */ -#define PPP_IPV6 0x0057 /* Internet Protocol version 6 */ -#define PPP_VJ_UCOMP 0x002f /* VJ uncompressed TCP/IP */ +#define PPP_IP 0x0021 /* Internet Protocol */ +#define PPP_IPV6 0x0057 /* Internet Protocol version 6 */ +#define PPP_VJ_UCOMP 0x002f /* VJ uncompressed TCP/IP */ /* Unsupported PPP types (libpcap source reference) */ -#define PPP_IPX 0x002b /* Novell IPX Protocol */ -#define PPP_VJ_COMP 0x002d /* VJ compressed TCP/IP */ -#define PPP_IPX 0x002b /* Novell IPX Protocol */ -#define PPP_OSI 0x0023 /* OSI Network Layer */ -#define PPP_NS 0x0025 /* Xerox NS IDP */ -#define PPP_DECNET 0x0027 /* DECnet Phase IV */ -#define PPP_APPLE 0x0029 /* Appletalk */ -#define PPP_BRPDU 0x0031 /* Bridging PDU */ -#define PPP_STII 0x0033 /* Stream Protocol (ST-II) */ -#define PPP_VINES 0x0035 /* Banyan Vines */ -#define PPP_HELLO 0x0201 /* 802.1d Hello Packets */ -#define PPP_LUXCOM 0x0231 /* Luxcom */ -#define PPP_SNS 0x0233 /* Sigma Network Systems */ -#define PPP_MPLS_UCAST 0x0281 /* rfc 3032 */ -#define PPP_MPLS_MCAST 0x0283 /* rfc 3022 */ -#define PPP_IPCP 0x8021 /* IP Control Protocol */ -#define PPP_OSICP 0x8023 /* OSI Network Layer Control Protocol */ -#define PPP_NSCP 0x8025 /* Xerox NS IDP Control Protocol */ -#define PPP_DECNETCP 0x8027 /* DECnet Control Protocol */ -#define PPP_APPLECP 0x8029 /* Appletalk Control Protocol */ -#define PPP_IPXCP 0x802b /* Novell IPX Control Protocol */ -#define PPP_STIICP 0x8033 /* Strean Protocol Control Protocol */ -#define PPP_VINESCP 0x8035 /* Banyan Vines Control Protocol */ -#define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */ -#define PPP_MPLSCP 0x8281 /* rfc 3022 */ -#define PPP_LCP 0xc021 /* Link Control Protocol */ -#define PPP_PAP 0xc023 /* Password Authentication Protocol */ -#define PPP_LQM 0xc025 /* Link Quality Monitoring */ -#define PPP_CHAP 0xc223 /* Challenge Handshake Authentication Protocol */ - -typedef struct _PPPHdr { +#define PPP_IPX 0x002b /* Novell IPX Protocol */ +#define PPP_VJ_COMP 0x002d /* VJ compressed TCP/IP */ +#define PPP_IPX 0x002b /* Novell IPX Protocol */ +#define PPP_OSI 0x0023 /* OSI Network Layer */ +#define PPP_NS 0x0025 /* Xerox NS IDP */ +#define PPP_DECNET 0x0027 /* DECnet Phase IV */ +#define PPP_APPLE 0x0029 /* Appletalk */ +#define PPP_BRPDU 0x0031 /* Bridging PDU */ +#define PPP_STII 0x0033 /* Stream Protocol (ST-II) */ +#define PPP_VINES 0x0035 /* Banyan Vines */ +#define PPP_HELLO 0x0201 /* 802.1d Hello Packets */ +#define PPP_LUXCOM 0x0231 /* Luxcom */ +#define PPP_SNS 0x0233 /* Sigma Network Systems */ +#define PPP_MPLS_UCAST 0x0281 /* rfc 3032 */ +#define PPP_MPLS_MCAST 0x0283 /* rfc 3022 */ +#define PPP_IPCP 0x8021 /* IP Control Protocol */ +#define PPP_OSICP 0x8023 /* OSI Network Layer Control Protocol */ +#define PPP_NSCP 0x8025 /* Xerox NS IDP Control Protocol */ +#define PPP_DECNETCP 0x8027 /* DECnet Control Protocol */ +#define PPP_APPLECP 0x8029 /* Appletalk Control Protocol */ +#define PPP_IPXCP 0x802b /* Novell IPX Control Protocol */ +#define PPP_STIICP 0x8033 /* Strean Protocol Control Protocol */ +#define PPP_VINESCP 0x8035 /* Banyan Vines Control Protocol */ +#define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */ +#define PPP_MPLSCP 0x8281 /* rfc 3022 */ +#define PPP_LCP 0xc021 /* Link Control Protocol */ +#define PPP_PAP 0xc023 /* Password Authentication Protocol */ +#define PPP_LQM 0xc025 /* Link Quality Monitoring */ +#define PPP_CHAP 0xc223 /* Challenge Handshake Authentication Protocol */ + +typedef struct PPPHdr_ { u_int8_t address; u_int8_t control; u_int16_t protocol; } PPPHdr; -#define PPP_HEADER_LEN (sizeof(struct _PPPHdr)) +#define PPP_HEADER_LEN 4 void DecodePPPRegisterTests(void); diff --git a/src/decode-tcp.h b/src/decode-tcp.h index a1adc3e2a8..418b8714cf 100644 --- a/src/decode-tcp.h +++ b/src/decode-tcp.h @@ -71,13 +71,13 @@ #define TCP_ISSET_FLAG_RES2(p) ((p)->tcph->th_flags & TH_RES2) #define TCP_ISSET_FLAG_RES1(p) ((p)->tcph->th_flags & TH_RES1) -typedef struct _TCPOpt { +typedef struct TCPOpt_ { u_int8_t type; u_int8_t len; u_int8_t *data; } TCPOpt; -typedef struct _TCPHdr +typedef struct TCPHdr_ { u_int16_t th_sport; /* source port */ u_int16_t th_dport; /* destination port */ @@ -90,7 +90,7 @@ typedef struct _TCPHdr u_int16_t th_urp; /* urgent pointer */ } TCPHdr; -typedef struct _TCPVars +typedef struct TCPVars_ { u_int8_t hlen; diff --git a/src/decode-udp.h b/src/decode-udp.h index 371a05c95b..d1c984958c 100644 --- a/src/decode-udp.h +++ b/src/decode-udp.h @@ -15,7 +15,7 @@ #define UDP_GET_DST_PORT(p) UDP_GET_RAW_DST_PORT(p->udph) /* UDP header structure */ -typedef struct _UDPHdr +typedef struct UDPHdr_ { u_int16_t uh_sport; /* source port */ u_int16_t uh_dport; /* destination port */ @@ -23,7 +23,7 @@ typedef struct _UDPHdr u_int16_t uh_sum; /* checksum */ } UDPHdr; -typedef struct _UDPVars +typedef struct UDPVars_ { u_int8_t hlen; } UDPVars; diff --git a/src/decode.h b/src/decode.h index a678cee599..999309f7d7 100644 --- a/src/decode.h +++ b/src/decode.h @@ -44,7 +44,7 @@ #include "decode-udp.h" /* Address */ -typedef struct _Address +typedef struct Address_ { char family; union { @@ -152,7 +152,7 @@ typedef u_int16_t Port; /* structure to store the sids/gids/etc the detection engine * found in this packet */ -typedef struct _PacketAlert { +typedef struct PacketAlert_ { u_int8_t gid; u_int32_t sid; u_int8_t rev; @@ -163,7 +163,7 @@ typedef struct _PacketAlert { #define PACKET_ALERT_MAX 256 -typedef struct _PacketAlerts { +typedef struct PacketAlerts_ { u_int16_t cnt; PacketAlert alerts[PACKET_ALERT_MAX]; } PacketAlerts; @@ -171,7 +171,7 @@ typedef struct _PacketAlerts { #define HTTP_URI_MAXCNT 8 #define HTTP_URI_MAXLEN 1024 -typedef struct _HttpUri { +typedef struct HttpUri_ { /* the raw uri for the packet as set by pcre */ u_int8_t *raw[HTTP_URI_MAXCNT]; u_int16_t raw_size[HTTP_URI_MAXCNT]; @@ -183,16 +183,16 @@ typedef struct _HttpUri { u_int8_t cnt; } HttpUri; -typedef struct _PktVar { +typedef struct PktVar_ { char *name; u_int8_t *value; u_int16_t value_len; - struct _PktVar *next; /* right now just implement this as a list, + struct PktVar_ *next; /* right now just implement this as a list, * in the long run we have thing of something * faster. */ } PktVar; -typedef struct _Packet +typedef struct Packet_ { /* Addresses, Ports and protocol * these are on top so we can use @@ -232,7 +232,7 @@ typedef struct _Packet u_int16_t pktlen; /* flow */ - struct _Flow *flow; + struct Flow_ *flow; u_int8_t flowflags; /* pkt vars */ @@ -276,11 +276,11 @@ typedef struct _Packet int action; /* double linked list ptrs */ - struct _Packet *next; - struct _Packet *prev; + struct Packet_ *next; + struct Packet_ *prev; /* tunnel/encapsulation handling */ - struct _Packet *root; /* in case of tunnel this is a ptr + struct Packet_ *root; /* in case of tunnel this is a ptr * to the 'real' packet, the one we * need to set the verdict on -- * It should always point to the lowest @@ -288,7 +288,7 @@ typedef struct _Packet } Packet; -typedef struct _PacketQueue { +typedef struct PacketQueue_ { Packet *top; Packet *bot; u_int16_t len; diff --git a/src/detect-content.h b/src/detect-content.h index 8194829ccc..97d7ac777c 100644 --- a/src/detect-content.h +++ b/src/detect-content.h @@ -10,7 +10,7 @@ #define DETECT_CONTENT_RAWBYTES 0x20 -typedef struct _DetectContentData { +typedef struct DetectContentData_ { u_int8_t *content; u_int8_t content_len; u_int32_t id; diff --git a/src/detect-dsize.h b/src/detect-dsize.h index 94072baf05..96d423432b 100644 --- a/src/detect-dsize.h +++ b/src/detect-dsize.h @@ -6,7 +6,7 @@ #define DETECTDSIZE_GT 2 #define DETECTDSIZE_RA 3 -typedef struct _DetectDsizeData { +typedef struct DetectDsizeData_ { u_int16_t dsize; u_int16_t dsize2; u_int8_t mode; diff --git a/src/detect-engine-mpm.c b/src/detect-engine-mpm.c index 2afade4d2d..0fea273888 100644 --- a/src/detect-engine-mpm.c +++ b/src/detect-engine-mpm.c @@ -182,7 +182,7 @@ void SigGroupHeadSetMpmMaxlen(DetectEngineCtx *de_ctx, SigGroupHead *sgh) } } -typedef struct _ContentHash { +typedef struct ContentHash_ { DetectContentData *ptr; u_int16_t cnt; u_int8_t use; /* use no matter what */ diff --git a/src/detect-flow.h b/src/detect-flow.h index 023de010fd..57e6dcbd0e 100644 --- a/src/detect-flow.h +++ b/src/detect-flow.h @@ -1,7 +1,7 @@ #ifndef __DETECT_FLOW_H__ #define __DETECT_FLOW_H__ -typedef struct _DetectFlowData { +typedef struct DetectFlowData_ { u_int8_t flags; /* flags to match */ u_int8_t match_cnt; /* number of matches we need */ } DetectFlowData; diff --git a/src/detect-flowbits.h b/src/detect-flowbits.h index f1d211e604..4ee85cb9a5 100644 --- a/src/detect-flowbits.h +++ b/src/detect-flowbits.h @@ -8,7 +8,7 @@ #define DETECT_FLOWBITS_CMD_TOGGLE 4 #define DETECT_FLOWBITS_CMD_NOALERT 5 -typedef struct _DetectFlowbitsData { +typedef struct DetectFlowbitsData_ { u_int16_t idx; u_int8_t cmd; } DetectFlowbitsData; diff --git a/src/detect-flowvar.h b/src/detect-flowvar.h index 5ff008bc2d..9927e43864 100644 --- a/src/detect-flowvar.h +++ b/src/detect-flowvar.h @@ -3,7 +3,7 @@ #define DETECT_CONTENT_NOCASE 0x01 -typedef struct _DetectFlowvarData { +typedef struct DetectFlowvarData_ { char *name; u_int16_t idx; u_int8_t *content; diff --git a/src/detect-pcre.h b/src/detect-pcre.h index 276806241b..08bb7bb79e 100644 --- a/src/detect-pcre.h +++ b/src/detect-pcre.h @@ -14,7 +14,7 @@ #define DETECT_PCRE_CAPTURE_PKT 0x0080 #define DETECT_PCRE_CAPTURE_FLOW 0x0100 -typedef struct _DetectPcreData { +typedef struct DetectPcreData_ { /* pcre options */ pcre *re; pcre_extra *sd; diff --git a/src/detect-pktvar.h b/src/detect-pktvar.h index 5cf93bd08f..5c9bd2cdf4 100644 --- a/src/detect-pktvar.h +++ b/src/detect-pktvar.h @@ -3,7 +3,7 @@ #define DETECT_CONTENT_NOCASE 0x01 -typedef struct _DetectPktvarData { +typedef struct DetectPktvarData_ { char *name; u_int8_t *content; u_int8_t content_len; diff --git a/src/detect-uricontent.h b/src/detect-uricontent.h index 2fb2b81788..b8f42e0aec 100644 --- a/src/detect-uricontent.h +++ b/src/detect-uricontent.h @@ -10,7 +10,7 @@ #define DETECT_URICONTENT_RAWBYTES 0x20 -typedef struct _DetectUricontentData { +typedef struct DetectUricontentData_ { u_int8_t *uricontent; u_int8_t uricontent_len; u_int32_t id; diff --git a/src/detect.h b/src/detect.h index 13ef5dcdb9..8d9a8cd575 100644 --- a/src/detect.h +++ b/src/detect.h @@ -43,12 +43,12 @@ typedef struct DetectAddressGroup_ { DetectAddressData *ad; /* XXX ptr to rules, or PortGroup or whatever */ -union { - struct DetectAddressGroupsHead_ *dst_gh; - struct DetectPort_ *port; -}; + union { + struct DetectAddressGroupsHead_ *dst_gh; + struct DetectPort_ *port; + }; /* signatures that belong in this group */ - struct _SigGroupHead *sh; + struct SigGroupHead_ *sh; u_int8_t flags; /* double linked list */ @@ -93,7 +93,7 @@ typedef struct DetectPort_ { u_int16_t port2; /* signatures that belong in this group */ - struct _SigGroupHead *sh; + struct SigGroupHead_ *sh; struct DetectPort_ *dst_ph; @@ -126,7 +126,11 @@ typedef struct DetectEngineIPOnlyThreadCtx_ { u_int32_t sig_match_size; /* size in bytes of the array */ } DetectEngineIPOnlyThreadCtx; -typedef struct _PatternMatcherThread { +/** + * Detection engine thread data. + * XXX: we should rename this + */ +typedef struct PatternMatcherThread_ { /* detection engine variables */ u_int8_t *pkt_ptr; /* ptr to the current position in the pkt */ u_int16_t pkt_off; @@ -142,7 +146,7 @@ typedef struct _PatternMatcherThread { * or uricontent ctx. */ MpmThreadCtx mtc; /* thread ctx for the mpm */ MpmThreadCtx mtcu; - struct _SigGroupHead *sgh; + struct SigGroupHead_ *sgh; PatternMatcherQueue pmq; /* counters */ @@ -174,7 +178,7 @@ typedef struct _PatternMatcherThread { } PatternMatcherThread; -typedef struct _Signature { +typedef struct Signature_ { u_int16_t flags; u_int32_t num; /* signature number, internal id */ @@ -188,8 +192,8 @@ typedef struct _Signature { DetectProto proto; DetectPort *sp, *dp; - struct _SigMatch *match; - struct _Signature *next; + struct SigMatch_ *match; + struct Signature_ *next; } Signature; typedef struct DetectEngineIPOnlyCtx_ { @@ -247,8 +251,6 @@ typedef struct DetectEngineCtx_ { u_int32_t signum; /* main sigs */ -// DetectAddressGroupsHead *src_gh[256]; /* a head for each protocol */ -// DetectAddressGroupsHead *tmp_gh[256]; DetectEngineLookupDsize dsize_gh[DSIZE_STATES]; u_int32_t mpm_unique, mpm_reuse, mpm_none, @@ -283,14 +285,14 @@ typedef struct DetectEngineCtx_ { DetectEngineIPOnlyCtx io_ctx; } DetectEngineCtx; -typedef struct _SigMatch { +typedef struct SigMatch_ { u_int8_t type; void *ctx; - struct _SigMatch *next; - struct _SigMatch *prev; + struct SigMatch_ *next; + struct SigMatch_ *prev; } SigMatch; -typedef struct SigTableElmt { +typedef struct SigTableElmt_ { int (*Match)(ThreadVars *, PatternMatcherThread *, Packet *, Signature *, SigMatch *); int (*Setup)(DetectEngineCtx *, Signature *, SigMatch *, char *); int (*Free)(SigMatch *); @@ -309,7 +311,7 @@ typedef struct SigTableElmt { #define SIG_GROUP_HEAD_MPM_URI_NOSCAN 0x40 /* head of the list of containers. */ -typedef struct _SigGroupHead { +typedef struct SigGroupHead_ { u_int8_t flags; /* pattern matcher instance */ diff --git a/src/flow-bit.h b/src/flow-bit.h index 6f9bb71711..6e31776166 100644 --- a/src/flow-bit.h +++ b/src/flow-bit.h @@ -5,7 +5,7 @@ #include "flow.h" #include "util-var.h" -typedef struct _FlowBit { +typedef struct FlowBit_ { u_int8_t type; /* type, DETECT_FLOWBITS in this case */ u_int16_t idx; /* name idx */ GenericVar *next; /* right now just implement this as a list, diff --git a/src/flow-hash.h b/src/flow-hash.h index d090bcfe47..dee17c6f4a 100644 --- a/src/flow-hash.h +++ b/src/flow-hash.h @@ -7,7 +7,7 @@ * Each bucket contains a flow or list of flows. All these flows have * the same hashkey (the hash is a chained hash). When doing modifications * to the list, the entire bucket is locked. */ -typedef struct _FlowBucket { +typedef struct FlowBucket_ { Flow *f; pthread_mutex_t m; } FlowBucket; diff --git a/src/flow-queue.h b/src/flow-queue.h index 5a98998ad7..f4b5778f9d 100644 --- a/src/flow-queue.h +++ b/src/flow-queue.h @@ -6,7 +6,7 @@ #include "flow.h" /* Define a queue for storing flows */ -typedef struct _FlowQueue +typedef struct FlowQueue_ { Flow *top; Flow *bot; diff --git a/src/flow-var.h b/src/flow-var.h index c404aea7cf..2ead171103 100644 --- a/src/flow-var.h +++ b/src/flow-var.h @@ -5,7 +5,7 @@ #include "flow.h" #include "util-var.h" -typedef struct _FlowVar { +typedef struct FlowVar_ { u_int8_t type; /* type, DETECT_FLOWVAR in this case */ u_int16_t idx; /* name idx */ GenericVar *next; /* right now just implement this as a list, diff --git a/src/flow.h b/src/flow.h index 9f71224fb2..cbb2e24a3b 100644 --- a/src/flow.h +++ b/src/flow.h @@ -15,7 +15,7 @@ #define FLOW_PKT_TOCLIENT_IPONLY_SET 0x20 /* global flow config */ -typedef struct _FlowCnf +typedef struct FlowCnf_ { u_int32_t hash_rand; u_int32_t hash_size; @@ -33,7 +33,7 @@ typedef struct _FlowCnf } FlowConfig; /* Hash key for the flow hash */ -typedef struct _FlowKey +typedef struct FlowKey_ { Address src, dst; Port sp, dp; @@ -42,7 +42,7 @@ typedef struct _FlowKey } FlowKey; -typedef struct _Flow +typedef struct Flow_ { Address src, dst; Port sp, dp; @@ -70,12 +70,12 @@ typedef struct _Flow /* list flow ptrs * NOTE!!! These are NOT protected by the * above mutex, but by the FlowQ's */ - struct _Flow *hnext; /* hash list */ - struct _Flow *hprev; - struct _Flow *lnext; /* list */ - struct _Flow *lprev; + struct Flow_ *hnext; /* hash list */ + struct Flow_ *hprev; + struct Flow_ *lnext; /* list */ + struct Flow_ *lprev; - struct _FlowBucket *fb; + struct FlowBucket_ *fb; } Flow; void FlowHandlePacket (ThreadVars *, Packet *); diff --git a/src/host.h b/src/host.h index fe644d4028..a15d6f150e 100644 --- a/src/host.h +++ b/src/host.h @@ -6,7 +6,7 @@ #include "util-hash.h" #include "util-bloomfilter-counting.h" -typedef struct _HostTable { +typedef struct HostTable_ { pthread_mutex_t m; /* storage & lookup */ @@ -16,7 +16,7 @@ typedef struct _HostTable { u_int32_t cnt; } HostTable; -typedef struct _Host { +typedef struct Host_ { pthread_mutex_t m; Address addr; diff --git a/src/l7-app-detect.c b/src/l7-app-detect.c index d5f4538ed7..2ee0006c08 100644 --- a/src/l7-app-detect.c +++ b/src/l7-app-detect.c @@ -20,7 +20,7 @@ static u_int8_t l7_proto_id = 0; -typedef struct _L7AppDetectDataProto { +typedef struct L7AppDetectDataProto_ { u_int8_t proto; } L7AppDetectDataProto; diff --git a/src/log-httplog.c b/src/log-httplog.c index 1f978d6387..f933bd9bad 100644 --- a/src/log-httplog.c +++ b/src/log-httplog.c @@ -60,7 +60,7 @@ void TmModuleLogHttplogIPv6Register (void) { tmm_modules[TMM_LOGHTTPLOG6].RegisterTests = NULL; } -typedef struct _LogHttplogThread { +typedef struct LogHttplogThread_ { FILE *fp; u_int32_t uri_cnt; } LogHttplogThread; diff --git a/src/packet-queue.h b/src/packet-queue.h index de27c2df19..fb5e36ba2d 100644 --- a/src/packet-queue.h +++ b/src/packet-queue.h @@ -8,7 +8,7 @@ /* XXX: moved to decode.h */ #if 0 -typedef struct _PacketQueue { +typedef struct PacketQueue_ { Packet *top; Packet *bot; u_int16_t len; diff --git a/src/respond-reject-libnet11.c b/src/respond-reject-libnet11.c index 3dfa1daae7..cb04d98de5 100644 --- a/src/respond-reject-libnet11.c +++ b/src/respond-reject-libnet11.c @@ -32,7 +32,7 @@ #include "respond-reject.h" #include "respond-reject-libnet11.h" -typedef struct _Libnet11Packet +typedef struct Libnet11Packet_ { u_int32_t ack, seq; u_int16_t window, dsize; diff --git a/src/source-nfq.h b/src/source-nfq.h index 958b442ac2..f70b2d4fe8 100644 --- a/src/source-nfq.h +++ b/src/source-nfq.h @@ -12,7 +12,7 @@ /* idea: set the recv-thread id in the packet to * select an verdict-queue */ -typedef struct _NFQPacketVars +typedef struct NFQPacketVars_ { int id; /* this nfq packets id */ @@ -22,7 +22,7 @@ typedef struct _NFQPacketVars u_int16_t hw_protocol; } NFQPacketVars; -typedef struct _NFQThreadVars +typedef struct NFQThreadVars_ { struct nfq_handle *h; struct nfnl_handle *nh; @@ -47,7 +47,7 @@ typedef struct _NFQThreadVars ThreadVars *tv; } NFQThreadVars; -typedef struct _NFQGlobalVars +typedef struct NFQGlobalVars_ { char unbind; } NFQGlobalVars; diff --git a/src/source-pcap.h b/src/source-pcap.h index 98bcfb4049..3059d18eb5 100644 --- a/src/source-pcap.h +++ b/src/source-pcap.h @@ -12,7 +12,7 @@ void TmModuleDecodePcapRegister (void); #define LIBPCAP_PROMISC 1 /* per packet Pcap vars */ -typedef struct _PcapPacketVars +typedef struct PcapPacketVars_ { int datalink; /* datalink from libpcap */ } PcapPacketVars; diff --git a/src/stream-tcp-private.h b/src/stream-tcp-private.h index 40e674ce17..01248eb592 100644 --- a/src/stream-tcp-private.h +++ b/src/stream-tcp-private.h @@ -1,16 +1,16 @@ #ifndef __STREAM_TCP_PRIVATE_H__ #define __STREAM_TCP_PRIVATE_H__ -typedef struct _TcpSegment { +typedef struct TcpSegment_ { u_int8_t *payload; u_int16_t payload_len; /* actual size of the payload */ u_int32_t seq; u_int16_t pool_size; /* size of the memory */ - struct _TcpSegment *next; - struct _TcpSegment *prev; + struct TcpSegment_ *next; + struct TcpSegment_ *prev; } TcpSegment; -typedef struct _TcpStream { +typedef struct TcpStream_ { u_int32_t isn; /* initial sequence number */ u_int32_t next_seq; /* next expected sequence number */ u_int32_t last_ack; /* last ack'd sequence number */ @@ -47,7 +47,7 @@ enum #define SEQ_GT(a,b) ((int)((a) - (b)) > 0) #define SEQ_GEQ(a,b) ((int)((a) - (b)) >= 0) -typedef struct _TcpSession { +typedef struct TcpSession_ { u_int8_t state; TcpStream server; TcpStream client; diff --git a/src/stream-tcp.c b/src/stream-tcp.c index 77b4b9ce7b..d28b3e17ec 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -65,7 +65,7 @@ void TmModuleStreamTcpRegister (void) { pthread_mutex_init(&ssn_pool_mutex, NULL); } -typedef struct _StreamTcpThread { +typedef struct StreamTcpThread_ { u_int64_t pkts; } StreamTcpThread; diff --git a/src/stream.h b/src/stream.h index add0bf9583..d811e94729 100644 --- a/src/stream.h +++ b/src/stream.h @@ -13,7 +13,7 @@ #define MSG_DATA_SIZE 512 -typedef struct _StreamMsg { +typedef struct StreamMsg_ { u_int32_t id; /* unique stream id */ u_int8_t flags; /* msg flags */ Flow *flow; /* parent flow */ @@ -32,11 +32,11 @@ typedef struct _StreamMsg { } gap; }; - struct _StreamMsg *next; - struct _StreamMsg *prev; + struct StreamMsg_ *next; + struct StreamMsg_ *prev; } StreamMsg; -typedef struct _StreamMsgQueue { +typedef struct StreamMsgQueue_ { StreamMsg *top; StreamMsg *bot; u_int16_t len; diff --git a/src/threadvars.h b/src/threadvars.h index b58bc8bfbe..97db9b81dc 100644 --- a/src/threadvars.h +++ b/src/threadvars.h @@ -11,7 +11,7 @@ #define THV_KILL 0x02 #define THV_CLOSED 0x04 /* thread done, should be joinable */ -typedef struct _ThreadVars { +typedef struct ThreadVars_ { pthread_t t; char *name; u_int8_t flags; @@ -21,8 +21,8 @@ typedef struct _ThreadVars { Tmq *outq; /* queue handlers */ - struct _Packet * (*tmqh_in)(struct _ThreadVars *); - void (*tmqh_out)(struct _ThreadVars *, struct _Packet *); + struct Packet_ * (*tmqh_in)(struct ThreadVars_ *); + void (*tmqh_out)(struct ThreadVars_ *, struct Packet_ *); /* slot functions */ void *(*tm_func)(void *); @@ -31,8 +31,8 @@ typedef struct _ThreadVars { char set_cpu_affinity; /* bool: 0 no, 1 yes */ int cpu_affinity; /* cpu or core to set affinity to */ - struct _ThreadVars *next; - struct _ThreadVars *prev; + struct ThreadVars_ *next; + struct ThreadVars_ *prev; } ThreadVars; #endif /* __THREADVARS_H__ */ diff --git a/src/tm-modules.h b/src/tm-modules.h index 72185f54f5..a65231d213 100644 --- a/src/tm-modules.h +++ b/src/tm-modules.h @@ -1,7 +1,7 @@ #ifndef __TM_MODULES_H__ #define __TM_MODULES_H__ -typedef struct _TmModule { +typedef struct TmModule_ { char *name; int (*Init)(ThreadVars *, void *, void **); int (*Func)(ThreadVars *, Packet *, void *, PacketQueue *); diff --git a/src/tm-queuehandlers.h b/src/tm-queuehandlers.h index caa2378fc7..93ae7fa83a 100644 --- a/src/tm-queuehandlers.h +++ b/src/tm-queuehandlers.h @@ -11,7 +11,7 @@ enum { TMQH_SIZE, }; -typedef struct _Tmqh { +typedef struct Tmqh_ { char *name; Packet *(*InHandler)(ThreadVars *); void (*OutHandler)(ThreadVars *, Packet *); diff --git a/src/tm-queues.h b/src/tm-queues.h index 1f1cd5a79f..95fb6ccf45 100644 --- a/src/tm-queues.h +++ b/src/tm-queues.h @@ -1,7 +1,7 @@ #ifndef __TM_QUEUES_H__ #define __TM_QUEUES_H__ -typedef struct _Tmq { +typedef struct Tmq_ { char *name; u_int16_t id; u_int16_t usecnt; diff --git a/src/tm-threads.c b/src/tm-threads.c index a2833757c3..52ffa249fd 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -19,7 +19,7 @@ static int SetCPUAffinity(int cpu); /* root of the threadvars list */ static ThreadVars *tv_root; -typedef struct _TmSlot { +typedef struct TmSlot_ { /* function pointers */ int (*SlotInit)(ThreadVars *, void *, void **); int (*SlotFunc)(ThreadVars *, Packet *, void *, PacketQueue *); @@ -32,26 +32,26 @@ typedef struct _TmSlot { PacketQueue slot_pq; /* linked list, only used by TmVarSlot */ - struct _TmSlot *slot_next; + struct TmSlot_ *slot_next; } TmSlot; /* 1 function slot */ -typedef struct _Tm1Slot { +typedef struct Tm1Slot_ { TmSlot s; } Tm1Slot; /* 2 function slot */ -typedef struct _Tm2Slot { +typedef struct Tm2Slot_ { TmSlot s1, s2; } Tm2Slot; /* 3 function slot */ -typedef struct _Tm3Slot { +typedef struct Tm3Slot_ { TmSlot s1, s2, s3; } Tm3Slot; /* Variable number of function slots */ -typedef struct _TmVarSlot { +typedef struct TmVarSlot_ { TmSlot *s; } TmVarSlot; diff --git a/src/util-bloomfilter-counting.h b/src/util-bloomfilter-counting.h index 9909b69ce6..c4cc1aad1a 100644 --- a/src/util-bloomfilter-counting.h +++ b/src/util-bloomfilter-counting.h @@ -4,7 +4,7 @@ #define __BLOOMFILTERCOUNTING_H__ /* Bloom filter structure */ -typedef struct _BloomFilterCounting { +typedef struct BloomFilterCounting_ { u_int8_t *array; u_int32_t array_size; /* size in buckets */ u_int8_t type; /* 1, 2 or 4 byte counters */ diff --git a/src/util-bloomfilter.h b/src/util-bloomfilter.h index 436340066c..3e5b35c182 100644 --- a/src/util-bloomfilter.h +++ b/src/util-bloomfilter.h @@ -4,7 +4,7 @@ #define __BLOOMFILTER_H__ /* Bloom Filter structure */ -typedef struct _BloomFilter { +typedef struct BloomFilter_ { u_int8_t *bitarray; u_int32_t bitarray_size; u_int8_t hash_iterations; diff --git a/src/util-hash.c b/src/util-hash.c index 4ed780ac32..d7edff7213 100644 --- a/src/util-hash.c +++ b/src/util-hash.c @@ -14,7 +14,7 @@ #include "util-unittest.h" -HashTable* HashTableInit(u_int32_t size, u_int32_t (*Hash)(struct _HashTable *, void *, u_int16_t), char (*Compare)(void *, u_int16_t, void *, u_int16_t), void (*Free)(void *)) { +HashTable* HashTableInit(u_int32_t size, u_int32_t (*Hash)(struct HashTable_ *, void *, u_int16_t), char (*Compare)(void *, u_int16_t, void *, u_int16_t), void (*Free)(void *)) { HashTable *ht = NULL; diff --git a/src/util-hash.h b/src/util-hash.h index 93006cab25..ce63fb679c 100644 --- a/src/util-hash.h +++ b/src/util-hash.h @@ -4,23 +4,23 @@ #define __HASH_H__ /* hash bucket structure */ -typedef struct _HashTableBucket { +typedef struct HashTableBucket_ { void *data; u_int16_t size; - struct _HashTableBucket *next; + struct HashTableBucket_ *next; } HashTableBucket; /* hash table structure */ -typedef struct _HashTable { +typedef struct HashTable_ { HashTableBucket **array; u_int32_t array_size; - u_int32_t (*Hash)(struct _HashTable *, void *, u_int16_t); + u_int32_t (*Hash)(struct HashTable_ *, void *, u_int16_t); char (*Compare)(void *, u_int16_t, void *, u_int16_t); void (*Free)(void *); } HashTable; /* prototypes */ -HashTable* HashTableInit(u_int32_t, u_int32_t (*Hash)(struct _HashTable *, void *, u_int16_t), char (*Compare)(void *, u_int16_t, void *, u_int16_t), void (*Free)(void *)); +HashTable* HashTableInit(u_int32_t, u_int32_t (*Hash)(struct HashTable_ *, void *, u_int16_t), char (*Compare)(void *, u_int16_t, void *, u_int16_t), void (*Free)(void *)); void HashTableFree(HashTable *); void HashTablePrint(HashTable *); int HashTableAdd(HashTable *, void *, u_int16_t); diff --git a/src/util-hashlist.c b/src/util-hashlist.c index df5a03a9bd..bee1e48770 100644 --- a/src/util-hashlist.c +++ b/src/util-hashlist.c @@ -14,7 +14,7 @@ #include "util-unittest.h" -HashListTable* HashListTableInit(u_int32_t size, u_int32_t (*Hash)(struct _HashListTable *, void *, u_int16_t), char (*Compare)(void *, u_int16_t, void *, u_int16_t), void (*Free)(void *)) { +HashListTable* HashListTableInit(u_int32_t size, u_int32_t (*Hash)(struct HashListTable_ *, void *, u_int16_t), char (*Compare)(void *, u_int16_t, void *, u_int16_t), void (*Free)(void *)) { HashListTable *ht = NULL; diff --git a/src/util-hashlist.h b/src/util-hashlist.h index 1c96cac086..6f6a44490c 100644 --- a/src/util-hashlist.h +++ b/src/util-hashlist.h @@ -4,27 +4,27 @@ #define __HASHLIST_H__ /* hash bucket structure */ -typedef struct _HashListTableBucket { +typedef struct HashListTableBucket_ { void *data; u_int16_t size; - struct _HashListTableBucket *bucknext; - struct _HashListTableBucket *listnext; - struct _HashListTableBucket *listprev; + struct HashListTableBucket_ *bucknext; + struct HashListTableBucket_ *listnext; + struct HashListTableBucket_ *listprev; } HashListTableBucket; /* hash table structure */ -typedef struct _HashListTable { +typedef struct HashListTable_ { HashListTableBucket **array; HashListTableBucket *listhead; HashListTableBucket *listtail; u_int32_t array_size; - u_int32_t (*Hash)(struct _HashListTable *, void *, u_int16_t); + u_int32_t (*Hash)(struct HashListTable_ *, void *, u_int16_t); char (*Compare)(void *, u_int16_t, void *, u_int16_t); void (*Free)(void *); } HashListTable; /* prototypes */ -HashListTable* HashListTableInit(u_int32_t, u_int32_t (*Hash)(struct _HashListTable *, void *, u_int16_t), char (*Compare)(void *, u_int16_t, void *, u_int16_t), void (*Free)(void *)); +HashListTable* HashListTableInit(u_int32_t, u_int32_t (*Hash)(struct HashListTable_ *, void *, u_int16_t), char (*Compare)(void *, u_int16_t, void *, u_int16_t), void (*Free)(void *)); void HashListTableFree(HashListTable *); void HashListTablePrint(HashListTable *); int HashListTableAdd(HashListTable *, void *, u_int16_t); diff --git a/src/util-mpm-b2g.h b/src/util-mpm-b2g.h index 919d3669a0..1f1d966aaa 100644 --- a/src/util-mpm-b2g.h +++ b/src/util-mpm-b2g.h @@ -44,22 +44,22 @@ //#define B2G_SCAN2 //#define B2G_COUNTERS -typedef struct _B2gPattern { +typedef struct B2gPattern_ { u_int8_t flags; u_int16_t len; u_int8_t *cs; /* case sensitive */ u_int8_t *ci; /* case INsensitive */ - struct _B2gPattern *next; + struct B2gPattern_ *next; MpmEndMatch *em; } B2gPattern; -typedef struct _B2gHashItem_ { +typedef struct B2gHashItem_ { u_int16_t idx; - struct _B2gHashItem_ *nxt; + struct B2gHashItem_ *nxt; u_int8_t flags; } B2gHashItem; -typedef struct _B2gCtx { +typedef struct B2gCtx_ { B2G_TYPE *scan_B2G; B2G_TYPE scan_m; BloomFilter **scan_bloom; @@ -99,14 +99,14 @@ typedef struct _B2gCtx { u_int8_t search_s0; /* we store our own multi byte scan ptr here for B2gSearch1 */ - u_int32_t (*MBScan2)(struct _MpmCtx *, struct _MpmThreadCtx *, PatternMatcherQueue *, u_int8_t *, u_int16_t); - u_int32_t (*MBScan)(struct _MpmCtx *, struct _MpmThreadCtx *, PatternMatcherQueue *, u_int8_t *, u_int16_t); + u_int32_t (*MBScan2)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, u_int8_t *, u_int16_t); + u_int32_t (*MBScan)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, u_int8_t *, u_int16_t); /* we store our own multi byte search ptr here for B2gSearch1 */ - u_int32_t (*MBSearch)(struct _MpmCtx *, struct _MpmThreadCtx *, PatternMatcherQueue *, u_int8_t *, u_int16_t); + u_int32_t (*MBSearch)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, u_int8_t *, u_int16_t); } B2gCtx; -typedef struct _B2gThreadCtx { +typedef struct B2gThreadCtx_ { #ifdef B2G_COUNTERS u_int32_t scan_stat_pminlen_calls; u_int32_t scan_stat_pminlen_total; diff --git a/src/util-mpm-b3g.h b/src/util-mpm-b3g.h index 852c281c7f..2ee046e818 100644 --- a/src/util-mpm-b3g.h +++ b/src/util-mpm-b3g.h @@ -39,22 +39,22 @@ //#define B3G_COUNTERS -typedef struct _B3gPattern { +typedef struct B3gPattern_ { u_int8_t *cs; /* case sensitive */ u_int8_t *ci; /* case INsensitive */ u_int16_t len; - struct _B3gPattern *next; + struct B3gPattern_ *next; u_int8_t flags; MpmEndMatch *em; } B3gPattern; -typedef struct _B3gHashItem_ { +typedef struct B3gHashItem_ { u_int8_t flags; u_int16_t idx; - struct _B3gHashItem_ *nxt; + struct B3gHashItem_ *nxt; } B3gHashItem; -typedef struct _B3gCtx { +typedef struct B3gCtx_ { /* hash used during ctx initialization */ B3gPattern **init_hash; @@ -93,17 +93,17 @@ typedef struct _B3gCtx { B3gHashItem **search_hash2; /* we store our own multi byte scan ptr here for B3gSearch1 */ - u_int32_t (*MBScan2)(struct _MpmCtx *, struct _MpmThreadCtx *, PatternMatcherQueue *, u_int8_t *, u_int16_t); - u_int32_t (*MBScan)(struct _MpmCtx *, struct _MpmThreadCtx *, PatternMatcherQueue *, u_int8_t *, u_int16_t); + u_int32_t (*MBScan2)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, u_int8_t *, u_int16_t); + u_int32_t (*MBScan)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, u_int8_t *, u_int16_t); /* we store our own multi byte search ptr here for B3gSearch1 */ - u_int32_t (*MBSearch2)(struct _MpmCtx *, struct _MpmThreadCtx *, PatternMatcherQueue *, u_int8_t *, u_int16_t); - u_int32_t (*MBSearch)(struct _MpmCtx *, struct _MpmThreadCtx *, PatternMatcherQueue *, u_int8_t *, u_int16_t); + u_int32_t (*MBSearch2)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, u_int8_t *, u_int16_t); + u_int32_t (*MBSearch)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, u_int8_t *, u_int16_t); /* pattern arrays */ B3gPattern **parray; } B3gCtx; -typedef struct _B3gThreadCtx { +typedef struct B3gThreadCtx_ { #ifdef B3G_COUNTERS u_int32_t scan_stat_pminlen_calls; u_int32_t scan_stat_pminlen_total; diff --git a/src/util-mpm-trie.c b/src/util-mpm-trie.c deleted file mode 100644 index d17bd7b800..0000000000 --- a/src/util-mpm-trie.c +++ /dev/null @@ -1,1426 +0,0 @@ -/* Multi Pattern Matcher - * - * (c) 2008 Victor Julien - */ - -#include -#include -#include -#include -#include - -#include "util-mpm.h" -#include "util-mpm-trie.h" - -#include "util-unittest.h" - -/* XXX can be removed. */ -#if 0 -/* - * TODO/IDEAS/XXX - * - we know if we are interested in just the first match (simple content of - * also in more matches (within, distance, offset, depth, etc). Act on that. - * - Do the search on demand. - * - */ - -/* prototypes to be exported */ -void TrieInitCtx(MpmCtx *mpm_ctx); -void TrieThreadInitCtx(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, u_int32_t); -int TrieAddPattern(MpmCtx *mpm_ctx, u_int8_t *key, u_int16_t keylen, u_int32_t pid, u_int32_t sid); -int TrieAddPatternNocase(MpmCtx *mpm_ctx, u_int8_t *key, u_int16_t keylen, u_int32_t pid, u_int32_t sid); -u_int32_t TrieSearch(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *, u_int8_t *buf, u_int16_t buflen); -void TriePrintInfo(MpmCtx *mpm_ctx); -void TriePrintThreadInfo(MpmThreadCtx *mpm_ctx); -void TrieRegisterTests(void); - -/* uppercase to lowercase conversion lookup table */ -static u_int8_t lowercasetable[256]; -/* marco to do the actual lookup */ -#define trie_tolower(c) lowercasetable[(c)] - -void MpmTrieRegister (void) { - mpm_table[MPM_TRIE].name = "trie"; - mpm_table[MPM_TRIE].InitCtx = TrieInitCtx; - mpm_table[MPM_TRIE].InitThreadCtx = TrieThreadInitCtx; - mpm_table[MPM_TRIE].AddPattern = TrieAddPattern; - mpm_table[MPM_TRIE].AddPatternNocase = TrieAddPatternNocase; - mpm_table[MPM_TRIE].Prepare = NULL; - mpm_table[MPM_TRIE].Scan = TrieSearch; - mpm_table[MPM_TRIE].Search = TrieSearch; - mpm_table[MPM_TRIE].Cleanup = MpmMatchCleanup; - mpm_table[MPM_TRIE].PrintCtx = TriePrintInfo; - mpm_table[MPM_TRIE].PrintThreadCtx = TriePrintThreadInfo; - mpm_table[MPM_TRIE].RegisterUnittests = TrieRegisterTests; - - /* create table for O(1) lowercase conversion lookup */ - u_int8_t c = 0; - for ( ; c < 255; c++) { - if (c >= 'A' && c <= 'Z') - lowercasetable[c] = (c + ('a' - 'A')); - else - lowercasetable[c] = c; - } -} - -/* - * function implementations - */ - - -/* append an endmatch to a character node - * - * Only used in the initialization phase */ -static void TrieEndMatchAppend(MpmCtx *mpm_ctx, TrieCharacter *c, u_int32_t pid, u_int32_t sid) -{ - MpmEndMatch *em = MpmAllocEndMatch(mpm_ctx); - if (em == NULL) { - printf("ERROR: TrieAllocEndMatch failed\n"); - return; - } - - em->id = pid; - em->sig_id = sid; - - if (c->em == NULL) { - c->em = em; - return; - } - - MpmEndMatch *m = c->em; - while (m->next) { - m = m->next; - } - m->next = em; -} - -/* allocate a character node - * - * Only used in the initialization phase */ -static TrieCharacter *TrieAllocCharacter (MpmCtx *mpm_ctx) -{ - TrieCtx *trie_ctx = (TrieCtx *)mpm_ctx->ctx; - - TrieCharacter *c = malloc(sizeof(TrieCharacter)); - if (c == NULL) - return NULL; - - memset(c, 0, sizeof(TrieCharacter)); - - mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += sizeof(TrieCharacter); - - trie_ctx->characters++; - return c; -} - -static void TrieFreeCharacter (MpmCtx *mpm_ctx, TrieCharacter *c) { - if (c != NULL) { - int i = 0; - for (i = 0; i < 256; i++) { - TrieFreeCharacter(mpm_ctx, c->nc[i]); - } - - MpmEndMatchFreeAll(mpm_ctx,c->em); - - mpm_ctx->memory_cnt--; - mpm_ctx->memory_size -= sizeof(TrieCharacter); - free(c); - } -} - -/* add a keyword to the search tree - * - * Only used in the initialization phase */ -static int DoTrieAddPattern(MpmCtx *mpm_ctx, TrieCharacter *c, u_int8_t *key, - u_int16_t keylen, u_int32_t pid, u_int32_t sid, - char nocase) -{ -#ifdef DEBUG - /* DEBUG */ - { u_int16_t i; - for (i = 0; i < keylen; i++) { - printf("TrieAddPattern: "); - if (isprint(key[i])) { - printf("%c", key[i]); - } else { - printf("\\x%02u", key[i]); - } - printf(" (id %u)\n", id); } - } -#endif - - if (keylen > mpm_ctx->search_maxlen) - mpm_ctx->search_maxlen = keylen; - if (mpm_ctx->search_minlen == 0) - mpm_ctx->search_minlen = keylen; - if (keylen < mpm_ctx->search_minlen) - mpm_ctx->search_minlen = keylen; - - u_int16_t i; - u_int8_t ch; - u_int16_t lenleft = 0; - - /* ADD PATTERN */ - for (i = 0, lenleft = keylen; i < keylen; i++, lenleft--) { - - if (nocase) ch = trie_tolower(key[i]); /* for nocase, add keywords in lowercase */ - else ch = key[i]; - - if (c->nc[ch] == NULL) { - // printf("TrieAddPattern: Addending new Character for \\x%02u\n", ch); - - c->nc[ch] = TrieAllocCharacter(mpm_ctx); - if (c->nc[ch] == NULL) { - printf("ERROR: TrieAllocCharacter failed\n"); - return -1; - } - c->nc[ch]->min_matchlen_left = lenleft; - } else { - if (lenleft < c->nc[ch]->min_matchlen_left) - c->nc[ch]->min_matchlen_left = lenleft; - - // printf("TrieAddPattern: Using existing Character for \\x%02u\n", ch); - } - - /* set the endmatch */ - if (i == keylen - 1) { - // printf("TrieAddPattern: last char of keyword, now append an EndMatch\n"); - TrieEndMatchAppend(mpm_ctx, c->nc[ch], pid, sid); - } - - c = c->nc[ch]; - } - - if (pid > mpm_ctx->max_pattern_id) - mpm_ctx->max_pattern_id = pid; - - return 0; -} - -int TrieAddPattern(MpmCtx *mpm_ctx, u_int8_t *key, u_int16_t keylen, u_int32_t pid, u_int32_t sid) { - TrieCtx *trie_ctx = (TrieCtx *)mpm_ctx->ctx; - - trie_ctx->keywords++; - - return(DoTrieAddPattern(mpm_ctx, &trie_ctx->root, key, keylen, pid, sid, 0 /* no nocase */)); -} - -int TrieAddPatternNocase(MpmCtx *mpm_ctx, u_int8_t *key, u_int16_t keylen, u_int32_t pid, u_int32_t sid) { - TrieCtx *trie_ctx = (TrieCtx *)mpm_ctx->ctx; - - trie_ctx->nocase_keywords++; - - return(DoTrieAddPattern(mpm_ctx, &trie_ctx->nocase_root, key, keylen, pid, sid, 1 /* nocase */)); -} - -static void TrieDoPrint(TrieCharacter *c, int depth) -{ - int d; - u_int8_t i; - for (i = 0; i < 255; i++) { - if (c->nc[i] != NULL) { - for (d = depth; d; d--) printf(" "); - if (isprint(i)) printf("%c", i); - else printf("\\x%02u", i); - - printf("[%u] ", c->nc[i]->min_matchlen_left); - - if (c->nc[i]->em != NULL) { - MpmEndMatch *em = c->nc[i]->em; - while (em) { - printf("* (%u) ", em->id); - em = em->next; - } - printf("\n"); - } - else printf("\n"); - - TrieDoPrint(c->nc[i], depth+1); - } - } -} - -void TriePrintTree(TrieCharacter *root) -{ - TrieDoPrint(root,0); -} - -/* allocate a partial match - * - * used at search runtime */ -static TriePartialMatch *TrieAllocPartialMatch (MpmThreadCtx *trie_thread_ctx) -{ - TriePartialMatch *pm = malloc(sizeof(TriePartialMatch)); - if (pm == NULL) { - return NULL; - } - - trie_thread_ctx->memory_cnt++; - trie_thread_ctx->memory_size += sizeof(TriePartialMatch); - - return pm; -} - -/* dequeue from pmlist */ -#define MPM_PM_DEQUEUE(pmlist,item) { \ - if ((item)->prev != NULL) (item)->prev->next = (item)->next; \ - if ((item)->next != NULL) (item)->next->prev = (item)->prev; \ - if ((item) == (pmlist)) (pmlist) = (item)->next; \ - (item)->next = NULL; \ - (item)->prev = NULL; \ -} - -/* enqueue into pmlist */ -#define MPM_PM_ENQUEUE(list,item) { \ - if ((list) == NULL) { \ - (list) = (item); \ - (item)->prev = NULL; \ - (item)->next = NULL; \ - } else { \ - (list)->prev = (item); \ - (item)->next = (list); \ - (item)->prev = NULL; \ - (list) = (item); \ - } \ -} - -/* enqueue in spare list */ -#define MPM_SPARE_ENQUEUE(sparelist,item) { \ - if ((sparelist)->top != NULL) { \ - (item)->next = (sparelist)->top; \ - (sparelist)->top->prev = (item); \ - (sparelist)->top = (item); \ - } else { \ - (sparelist)->top = (item); } \ -} - -/* dequeue from spare list, or allocate a new pm */ -static inline TriePartialMatch * -TrieSpareDequeue (MpmThreadCtx *mpm_thread_ctx, TriePartialMatchList *q) -{ - TriePartialMatch *p = q->top; - if (p == NULL) - return TrieAllocPartialMatch(mpm_thread_ctx); - - if (q->top->next != NULL) { - q->top = q->top->next; - q->top->prev = NULL; - } else { - q->top = NULL; - } - - return p; -} - - -#define MAX_PREPEEK 5 - -static inline u_int32_t -TrieSearchCharNocase(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, - TrieThreadCtx *trie_thread_ctx, PatternMatcherQueue *pmq, - TrieCharacter *c, TriePartialMatch **qpm, u_int8_t ch) -{ - TriePartialMatch *tmppm, *tpm; - - //printf("TrieSearchChar: ch "); - //if (isprint(ch)) printf("%c", ch); - //else printf("%02X", ch); - //printf("\n"); - - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_nocase_cnt++; - #endif /* MPM_DBG_PERF */ - - /* First see if any of our partial matches is happy with - * the new character. */ - for (tmppm = *qpm; tmppm != NULL; ) { - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_nocase_pmloop_cnt++; - #endif /* MPM_DBG_PERF */ - - if (tmppm->c->nc[ch] != NULL) { - /* This PM is happy, lets see if it's done */ - MpmEndMatch *em = tmppm->c->nc[ch]->em; - if (em != NULL) { - for (; em != NULL; em = em->next) { - MpmMatchAppend(mpm_thread_ctx, pmq, em, &mpm_thread_ctx->match[em->id], - trie_thread_ctx->buf - trie_thread_ctx->bufmin); - - //printf("NOCASE MATCH! id %u, matched at offset %u, char %c\n", em->id, - // trie_thread_ctx->buf - mpm_thread_ctx->bufmin, *mpm_thread_ctx->buf); - mpm_thread_ctx->matches++; - } - - tpm = tmppm->next; - MPM_PM_DEQUEUE(*qpm,tmppm); - MPM_SPARE_ENQUEUE(&trie_thread_ctx->spare_queue,tmppm); - tmppm = tpm; - /* So far so good, but not yet done. */ - } else { - tmppm->c = tmppm->c->nc[ch]; - tmppm = tmppm->next; - } - } else { - /* No match, so this partial match can be removed - * as it will never be able to match anymore. */ - tpm = tmppm->next; - MPM_PM_DEQUEUE(*qpm,tmppm); - MPM_SPARE_ENQUEUE(&trie_thread_ctx->spare_queue,tmppm); - tmppm = tpm; - } - } - - if (c->nc[ch] != NULL) { - //printf("TrieSearchChar: c->nc[ch] != NULL\n"); - /* Match at root, so we may be at the start of a match - * - * First check if we may be looking for a single char - * match. In that case we have no need for creating a - * partial match. */ - MpmEndMatch *em = c->nc[ch]->em; - if (em != NULL) { - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_nocase_matchroot_cnt++; - #endif /* MPM_DBG_PERF */ - - for (; em != NULL; em = em->next) { - MpmMatchAppend(mpm_thread_ctx, pmq, em, &mpm_thread_ctx->match[em->id], - trie_thread_ctx->buf - trie_thread_ctx->bufmin); - //printf("NOCASE MATCH @search root! id %u, matched at offset %u, char %c\n", em->id, - // trie_thread_ctx->buf - mpm_thread_ctx->bufmin, *mpm_thread_ctx->buf); - mpm_thread_ctx->matches++; - } - /* Setup a partial match, unless we are at the end of - * the buffer. */ - } else if (trie_thread_ctx->buf != trie_thread_ctx->buflast) { - /* quick look forward, if the next doesn't match don't - * create a new patial match */ - TrieCharacter *tc; - int i = 1; /* start at offset 1 */ - - for (tc = c->nc[ch]->nc[trie_tolower(*(trie_thread_ctx->buf+i))]; - tc != NULL && i < MAX_PREPEEK && trie_thread_ctx->buf+i <= trie_thread_ctx->buflast; - i++, tc = tc->nc[trie_tolower(*(trie_thread_ctx->buf+i))]) - { - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_nocase_prepeek_cnt++; - #endif /* MPM_DBG_PERF */ - - /* check if we match here already */ - MpmEndMatch *nem = tc->em; - //printf("TrieSearchChar: i %d, tc %p, nem %p\n", i, tc, nem); - if (nem != NULL) { - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_nocase_prepeekmatch_cnt++; - #endif /* MPM_DBG_PERF */ - - for (; nem != NULL; nem = nem->next) { - MpmMatchAppend(mpm_thread_ctx, pmq, nem, &mpm_thread_ctx->match[nem->id], - trie_thread_ctx->buf - trie_thread_ctx->bufmin); - //printf("MATCH! id %u, matched at offset %u\n", nem->id, - // trie_thread_ctx->buf - mpm_thread_ctx->bufmin); - mpm_thread_ctx->matches++; - } - } else if ((trie_thread_ctx->buf+i) == trie_thread_ctx->buflast) { - //printf("TrieSearchChar: (trie_thread_ctx->buf+i) == mpm_thread_ctx->buflast: %p+%d == %p\n", mpm_thread_ctx->buf, i, mpm_thread_ctx->buflast); - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_nocase_prepeek_nomatchnobuf_cnt++; - #endif /* MPM_DBG_PERF */ - - tc = NULL; - break; - } else if (tc->min_matchlen_left > (trie_thread_ctx->buflast - (trie_thread_ctx->buf+i-1))) { - //printf("TrieSearchChar: tc->min_matchlen_left > (trie_thread_ctx->buflast - (mpm_thread_ctx->buf+i-1)): %u > %p - (%p + %d - 1 = %p) = %d\n", tc->min_matchlen_left, mpm_thread_ctx->buflast, mpm_thread_ctx->buf, i, mpm_thread_ctx->buf+i-1, (mpm_thread_ctx->buflast - (mpm_thread_ctx->buf+i-1))); - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_nocase_prepeek_nomatchbuflen_cnt++; - #endif /* MPM_DBG_PERF */ - - tc = NULL; - break; - } - } - /* if we still have a tc, setup a pm */ - if (tc != NULL) { - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_nocase_pmcreate_cnt++; - #endif /* MPM_DBG_PERF */ - - tpm = TrieSpareDequeue(mpm_thread_ctx, &trie_thread_ctx->spare_queue); - if (tpm != NULL) { - tpm->c = c->nc[ch]; - MPM_PM_ENQUEUE(*qpm,tpm); - } - } - } - } - return 0; -} - -static inline u_int32_t -TrieSearchChar(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, - TrieThreadCtx *trie_thread_ctx, PatternMatcherQueue *pmq, - TrieCharacter *c, TriePartialMatch **qpm, u_int8_t ch) -{ - TriePartialMatch *tmppm, *tpm; - - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_cnt++; - #endif /* MPM_DBG_PERF */ - -// printf("TrieSearchChar: ch "); -// if (isprint(ch)) printf("%c", ch); -// else printf("%02X", ch); -// printf("\n"); - - /* First see if any of our partial matches is happy with - * the new character. */ - for (tmppm = *qpm; tmppm != NULL; ) { - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_pmloop_cnt++; - #endif /* MPM_DBG_PERF */ - - if (tmppm->c->nc[ch] != NULL) { - /* This PM is happy, lets see if it's done */ - MpmEndMatch *em = tmppm->c->nc[ch]->em; - if (em != NULL) { - for (; em != NULL; em = em->next) { - MpmMatchAppend(mpm_thread_ctx, pmq, em, &mpm_thread_ctx->match[em->id], - trie_thread_ctx->buf - trie_thread_ctx->bufmin); - - //printf("MATCH! id %u, matched at offset %u, char %c\n", em->id, - // trie_thread_ctx->buf - mpm_thread_ctx->bufmin, *mpm_thread_ctx->buf); - mpm_thread_ctx->matches++; - } - - tpm = tmppm->next; - MPM_PM_DEQUEUE(*qpm,tmppm); - MPM_SPARE_ENQUEUE(&trie_thread_ctx->spare_queue,tmppm); - tmppm = tpm; - /* So far so good, but not yet done. */ - } else { - tmppm->c = tmppm->c->nc[ch]; - tmppm = tmppm->next; - } - } else { - /* No match, so this partial match can be removed - * as it will never be able to match anymore. */ - tpm = tmppm->next; - MPM_PM_DEQUEUE(*qpm,tmppm); - MPM_SPARE_ENQUEUE(&trie_thread_ctx->spare_queue,tmppm); - tmppm = tpm; - } - } - - if (c->nc[ch] != NULL) { -// printf("TrieSearchChar: c->nc[ch] != NULL\n"); - /* Match at root, so we may be at the start of a match - * - * First check if we may be looking for a single char - * match. In that case we have no need for creating a - * partial match. */ - MpmEndMatch *em = c->nc[ch]->em; - if (em != NULL) { - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_matchroot_cnt++; - #endif /* DBG_MPM_PERF */ - - for (; em != NULL; em = em->next) { - MpmMatchAppend(mpm_thread_ctx, pmq, em, &mpm_thread_ctx->match[em->id], - trie_thread_ctx->buf - trie_thread_ctx->bufmin); -// printf("MATCH! @search root id %u, matched at offset %u, char %c\n", em->id, -// trie_thread_ctx->buf - mpm_thread_ctx->bufmin, *mpm_thread_ctx->buf); - mpm_thread_ctx->matches++; - } - /* Setup a partial match, unless we are at the end of - * the buffer. */ - } else if (trie_thread_ctx->buf != trie_thread_ctx->buflast) { - /* quick look forward, if the next doesn't match don't - * create a new patial match */ - TrieCharacter *tc; - int i = 1; /* start at offset 1 */ - - for (tc = c->nc[ch]->nc[*(trie_thread_ctx->buf+i)]; - tc != NULL && i < MAX_PREPEEK && trie_thread_ctx->buf+i <= trie_thread_ctx->buflast; - i++, tc = tc->nc[*(trie_thread_ctx->buf+i)]) - { - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_prepeek_cnt++; - #endif /* MPM_DBG_PERF */ - - /* check if we match here already */ - MpmEndMatch *nem = tc->em; -// printf("TrieSearchChar: i %d ", i); -// printf("tc %p ", tc); -// printf("(left %u) ", tc->min_matchlen_left); -// printf("*(trie_thread_ctx->buf+i+1) %02X ", *(mpm_thread_ctx->buf+i)); -// printf("tc->nc[*(trie_thread_ctx->buf+i+1)] %p ", tc->nc[*(mpm_thread_ctx->buf+i)]); -// printf("nem %p\n", nem); - if (nem != NULL) { - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_prepeekmatch_cnt++; - #endif /* MPM_DBG_PERF */ - - for (; nem != NULL; nem = nem->next) { - MpmMatchAppend(mpm_thread_ctx, pmq, nem, &mpm_thread_ctx->match[nem->id], - trie_thread_ctx->buf - trie_thread_ctx->bufmin); -// printf("MATCH! id %u, matched at offset %u\n", nem->id, -// trie_thread_ctx->buf - mpm_thread_ctx->bufmin); - mpm_thread_ctx->matches++; - } - } else if ((trie_thread_ctx->buf+i) == trie_thread_ctx->buflast) { -// printf("TrieSearchChar: (trie_thread_ctx->buf+i) == mpm_thread_ctx->buflast: %p+%d == %p\n", mpm_thread_ctx->buf, i, mpm_thread_ctx->buflast); - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_prepeek_nomatchnobuf_cnt++; - #endif /* MPM_DBG_PERF */ - - tc = NULL; - break; - } else if (tc->min_matchlen_left > (trie_thread_ctx->buflast - (trie_thread_ctx->buf+i-1))) { -// printf("TrieSearchChar: tc->min_matchlen_left > (trie_thread_ctx->buflast - (mpm_thread_ctx->buf+i-1)): %u > %p - (%p + %d - 1 = %p) = %d\n", tc->min_matchlen_left, mpm_thread_ctx->buflast, mpm_thread_ctx->buf, i, mpm_thread_ctx->buf+i-1, (mpm_thread_ctx->buflast - (mpm_thread_ctx->buf+i-1))); - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_prepeek_nomatchbuflen_cnt++; - #endif /* MPM_DBG_PERF */ - - tc = NULL; - break; - } - } - /* if we still have a tc, setup a pm */ - if (tc != NULL) { - #ifdef MPM_DBG_PERF - trie_thread_ctx->searchchar_pmcreate_cnt++; - #endif /* MPM_DBG_PERF */ - - tpm = TrieSpareDequeue(mpm_thread_ctx, &trie_thread_ctx->spare_queue); - if (tpm != NULL) { - tpm->c = c->nc[ch]; - MPM_PM_ENQUEUE(*qpm,tpm); - } - } - } - } - return 0; -} - -/* TrieSearchOffsetDepth - * - * Returns: - * - number of match occurences in total (including multiple matches - * of the same keyword or even duplicate keywords). - * - 0 if no match at all - * - */ -u_int32_t -TrieSearchOffsetDepth(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, - u_int8_t *buf, u_int16_t buflen, u_int16_t offset, u_int16_t depth) -{ - TrieCtx *trie_ctx = (TrieCtx *)mpm_ctx->ctx; - TrieThreadCtx *trie_thread_ctx = (TrieThreadCtx *)mpm_thread_ctx->ctx; - - trie_thread_ctx->buf = buf + offset; - trie_thread_ctx->bufmin = buf + offset; - - if (depth) trie_thread_ctx->bufmax = buf + depth; - else trie_thread_ctx->bufmax = buf + buflen; - - trie_thread_ctx->buflast = trie_thread_ctx->bufmax - 1; - TriePartialMatch *tmppm, *tpm; - mpm_thread_ctx->matches = 0; - -#ifdef MPM_DBG_PERF - trie_thread_ctx->mpmsearchoffsetdepth++; -#endif /* MPM_DBG_PERF */ - - /* go through the buffer in one swell swoop and do our - * matching magic. Test both case and nocase together - * to prevent having to go through the buf twice */ - for ( ; trie_thread_ctx->buf != trie_thread_ctx->bufmax; - trie_thread_ctx->buf++) { - TrieSearchChar(mpm_ctx, mpm_thread_ctx, trie_thread_ctx, pmq, - &trie_ctx->root, &trie_thread_ctx->pmqueue, - *trie_thread_ctx->buf); - TrieSearchCharNocase(mpm_ctx, mpm_thread_ctx, trie_thread_ctx, pmq, - &trie_ctx->nocase_root, &trie_thread_ctx->nocase_pmqueue, - trie_tolower(*trie_thread_ctx->buf)); - } - - /* We reached the end of the buffer, clean up leftover - * partial matches that didn't match. */ - for (tmppm = trie_thread_ctx->pmqueue; tmppm != NULL; ) { - tpm = tmppm->next; - MPM_PM_DEQUEUE(trie_thread_ctx->pmqueue,tmppm); - MPM_SPARE_ENQUEUE(&trie_thread_ctx->spare_queue,tmppm); - tmppm = tpm; - } - for (tmppm = trie_thread_ctx->nocase_pmqueue; tmppm != NULL; ) { - tpm = tmppm->next; - MPM_PM_DEQUEUE(trie_thread_ctx->nocase_pmqueue,tmppm); - MPM_SPARE_ENQUEUE(&trie_thread_ctx->spare_queue,tmppm); - tmppm = tpm; - } - - return mpm_thread_ctx->matches; -} - -/* TrieSearch - * - * Returns: - * - number of match occurences in total (including multiple matches - * of the same keyword or even duplicate keywords). - * - 0 if no match at all - * - */ -u_int32_t -TrieSearch(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, - u_int8_t *buf, u_int16_t buflen) -{ - TrieCtx *trie_ctx = (TrieCtx *)mpm_ctx->ctx; - TrieThreadCtx *trie_thread_ctx = (TrieThreadCtx *)mpm_thread_ctx->ctx; - - trie_thread_ctx->buf = buf; - trie_thread_ctx->bufmin = buf; - trie_thread_ctx->bufmax = buf + buflen; - trie_thread_ctx->buflast = buf + buflen - 1; - TriePartialMatch *tmppm, *tpm; - mpm_thread_ctx->matches = 0; - -#ifdef MPM_DBG_PERF - trie_thread_ctx->mpmsearch++; -#endif /* MPM_DBG_PERF */ - - /* go through the buffer in one swell swoop and do our - * matching magic. Test both case and nocase together - * to prevent having to go through the buf twice */ - for ( ; trie_thread_ctx->buf != trie_thread_ctx->bufmax; - trie_thread_ctx->buf++) { - TrieSearchChar(mpm_ctx, mpm_thread_ctx, trie_thread_ctx, pmq, - &trie_ctx->root, &trie_thread_ctx->pmqueue, - *trie_thread_ctx->buf); - TrieSearchCharNocase(mpm_ctx, mpm_thread_ctx, trie_thread_ctx, pmq, - &trie_ctx->nocase_root, &trie_thread_ctx->nocase_pmqueue, - trie_tolower(*trie_thread_ctx->buf)); - } - - /* We reached the end of the buffer, clean up leftover - * partial matches that didn't match. */ - for (tmppm = trie_thread_ctx->pmqueue; tmppm != NULL; ) { - tpm = tmppm->next; - MPM_PM_DEQUEUE(trie_thread_ctx->pmqueue,tmppm); - MPM_SPARE_ENQUEUE(&trie_thread_ctx->spare_queue,tmppm); - tmppm = tpm; - } - for (tmppm = trie_thread_ctx->nocase_pmqueue; tmppm != NULL; ) { - tpm = tmppm->next; - MPM_PM_DEQUEUE(trie_thread_ctx->nocase_pmqueue,tmppm); - MPM_SPARE_ENQUEUE(&trie_thread_ctx->spare_queue,tmppm); - tmppm = tpm; - } - - return mpm_thread_ctx->matches; -} - -void TriePrintThreadInfo(MpmThreadCtx *mpm_ctx) { - printf("\nMPM Trie thread stats:\n"); - printf("Memory blocks: %u\n", mpm_ctx->memory_cnt); - printf("Memory size: %u\n", mpm_ctx->memory_size); -#ifdef MPM_DBG_PERF - TrieThreadCtx *trie_ctx = (TrieThreadCtx *)mpm_ctx->ctx; - - printf("triesearch %llu\n", mpm_ctx->mpmsearch); - printf("triesearchoffsetdepth %llu\n", mpm_ctx->mpmsearchoffsetdepth); - printf("searchchar_cnt %llu\n", trie_ctx->searchchar_cnt); - printf("searchchar_pmloop_cnt %llu\n", trie_ctx->searchchar_pmloop_cnt); - printf("searchchar_nocase_cnt %llu\n", trie_ctx->searchchar_nocase_cnt); - printf("searchchar_nocase_pmloop_cnt %llu\n", trie_ctx->searchchar_nocase_pmloop_cnt); - printf("searchchar_nocase_prepeek_cnt %llu\n", trie_ctx->searchchar_nocase_prepeek_cnt); - printf("searchchar_nocase_prepeekmatch_cnt %llu\n", trie_ctx->searchchar_nocase_prepeekmatch_cnt); - printf("searchchar_nocase_prepeek_nomatchnobuf_cnt %llu\n", trie_ctx->searchchar_nocase_prepeek_nomatchnobuf_cnt); - printf("searchchar_nocase_prepeek_nomatchbuflen_cnt %llu\n", trie_ctx->searchchar_nocase_prepeek_nomatchbuflen_cnt); - printf("searchchar_nocase_pmcreate_cnt %llu\n", trie_ctx->searchchar_nocase_pmcreate_cnt); - printf("searchchar_matchroot_cnt %llu\n", trie_ctx->searchchar_matchroot_cnt); - printf("searchchar_prepeek_cnt %llu\n", trie_ctx->searchchar_prepeek_cnt); - printf("searchchar_prepeekmatch_cnt %llu\n", trie_ctx->searchchar_prepeekmatch_cnt); - printf("searchchar_prepeek_nomatchnobuf_cnt %llu\n", trie_ctx->searchchar_prepeek_nomatchnobuf_cnt); - printf("searchchar_prepeek_nomatchbuflen_cnt %llu\n", trie_ctx->searchchar_prepeek_nomatchbuflen_cnt); - printf("searchchar_pmcreate_cnt %llu\n", trie_ctx->searchchar_pmcreate_cnt); -#endif /* MPM_DBG_PERF */ - printf("\n"); -} - -void TriePrintInfo(MpmCtx *mpm_ctx) { - TrieCtx *trie_ctx = (TrieCtx *)mpm_ctx->ctx; - - printf("\nMPM Trie stats:\n"); - printf("Patterns: %u\n", trie_ctx->keywords); - printf("Patterns Nocase: %u\n", trie_ctx->nocase_keywords); - printf(" -shortest len: %u\n", mpm_ctx->search_minlen); - printf(" -longest len: %u\n", mpm_ctx->search_maxlen); - printf("Characters: %u\n", trie_ctx->characters); - printf("EndMatches: %u\n", mpm_ctx->endmatches); - printf("Memory blocks: %u\n", mpm_ctx->memory_cnt); - printf("Memory size: %u\n", mpm_ctx->memory_size); -} - -void TrieInitCtx(MpmCtx *mpm_ctx) -{ - memset(mpm_ctx, 0, sizeof(MpmCtx)); - - mpm_ctx->ctx = malloc(sizeof(TrieCtx)); - if (mpm_ctx->ctx == NULL) - return; - - memset(mpm_ctx->ctx, 0, sizeof(TrieCtx)); -} - -void TrieDestroyCtx(MpmCtx *mpm_ctx) { - TrieCtx *trie_ctx = (TrieCtx *)mpm_ctx->ctx; - if (trie_ctx != NULL) { - int i; - for (i = 0; i < 256; i++) { - TrieFreeCharacter(mpm_ctx, trie_ctx->root.nc[i]); - TrieFreeCharacter(mpm_ctx, trie_ctx->nocase_root.nc[i]); - } - - mpm_ctx->memory_cnt--; - mpm_ctx->memory_size -= sizeof(TrieCtx); - free(trie_ctx); - mpm_ctx->ctx = NULL; - } -} - -void TrieThreadInitCtx(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, u_int32_t max_id) { - memset(mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); - - mpm_thread_ctx->ctx = malloc(sizeof(TrieThreadCtx)); - if (mpm_thread_ctx->ctx == NULL) - return; - - memset(mpm_thread_ctx->ctx, 0, sizeof(TrieThreadCtx)); - - mpm_thread_ctx->memory_cnt++; - mpm_thread_ctx->memory_size += sizeof(TrieThreadCtx); - - /* alloc an array with the size of _all_ keys in all instances. - * this is done so the detect engine won't have to care about - * what instance it's looking up in. The matches all have a - * unique id and is the array lookup key at the same time */ - //u_int32_t keys = mpm_ctx->max_pattern_id + 1; - u_int32_t keys = max_id + 1; - if (keys) { - mpm_thread_ctx->match = malloc(keys * sizeof(MpmMatchBucket)); - if (mpm_thread_ctx->match == NULL) { - printf("ERROR: could not setup memory for pattern matcher: %s\n", strerror(errno)); - exit(1); - } - memset(mpm_thread_ctx->match, 0, keys * sizeof(MpmMatchBucket)); - - mpm_thread_ctx->memory_cnt++; - mpm_thread_ctx->memory_size += (keys * sizeof(MpmMatchBucket)); - } -} - -void TrieThreadDestroyCtx(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx) { - TrieThreadCtx *trie_ctx = (TrieThreadCtx *)mpm_thread_ctx->ctx; - if (trie_ctx) { - if (mpm_thread_ctx->match != NULL) { - mpm_thread_ctx->memory_cnt--; - mpm_thread_ctx->memory_size -= ((mpm_ctx->max_pattern_id + 1) * sizeof(MpmMatchBucket)); - free(mpm_thread_ctx->match); - } - - mpm_thread_ctx->memory_cnt--; - mpm_thread_ctx->memory_size -= sizeof(TrieThreadCtx); - free(mpm_thread_ctx->ctx); - } - - MpmMatchFreeSpares(mpm_thread_ctx, mpm_thread_ctx->sparelist); - MpmMatchFreeSpares(mpm_thread_ctx, mpm_thread_ctx->qlist); -} - -/* - * ONLY TESTS BELOW THIS COMMENT - */ - - -int TrieTestInitCtx01 (void) { - int result = 0; - MpmCtx mpm_ctx; - TrieInitCtx(&mpm_ctx); - - if (mpm_ctx.ctx != NULL) - result = 1; - - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestInitCtx02 (void) { - int result = 0; - MpmCtx mpm_ctx; - TrieInitCtx(&mpm_ctx); - - TrieCtx *trie_ctx = (TrieCtx *)mpm_ctx.ctx; - - if (trie_ctx->characters == 0) - result = 1; - - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestInitCtx03 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - if (mpm_ctx.Search == TrieSearch) - result = 1; - - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestThreadInitCtx01 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - - MpmInitCtx(&mpm_ctx, MPM_TRIE); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - - if (mpm_thread_ctx.memory_cnt == 2) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestThreadInitCtx02 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - - MpmInitCtx(&mpm_ctx, MPM_TRIE); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - - TrieThreadCtx *trie_thread_ctx = (TrieThreadCtx *)mpm_thread_ctx.ctx; - - if (trie_thread_ctx->buf == NULL) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestInitAddPattern01 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - - MpmInitCtx(&mpm_ctx, MPM_TRIE); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - - int ret = TrieAddPattern(&mpm_ctx, (u_int8_t *)"abcd", 4, 1234, 0); - if (ret == 0) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestInitAddPattern02 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - - MpmInitCtx(&mpm_ctx, MPM_TRIE); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - TrieCtx *trie_ctx = (TrieCtx *)mpm_ctx.ctx; - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"abcd", 4, 1234, 0); - - if (trie_ctx->root.nc['a'] != NULL) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestInitAddPattern03 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - - MpmInitCtx(&mpm_ctx, MPM_TRIE); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - TrieCtx *trie_ctx = (TrieCtx *)mpm_ctx.ctx; - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"abcd", 4, 1234, 0); - - if (trie_ctx->root.nc['a']->min_matchlen_left == 4) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestInitAddPattern04 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - - MpmInitCtx(&mpm_ctx, MPM_TRIE); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - TrieCtx *trie_ctx = (TrieCtx *)mpm_ctx.ctx; - - TrieAddPatternNocase(&mpm_ctx, (u_int8_t *)"abcd", 4, 1234, 0); - - if (trie_ctx->nocase_root.nc['a'] != NULL) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestInitAddPattern05 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - - MpmInitCtx(&mpm_ctx, MPM_TRIE); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - TrieCtx *trie_ctx = (TrieCtx *)mpm_ctx.ctx; - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"Abcd", 4, 1234, 0); - - if (trie_ctx->root.nc['A'] != NULL) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestInitAddPattern06 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - - MpmInitCtx(&mpm_ctx, MPM_TRIE); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - TrieCtx *trie_ctx = (TrieCtx *)mpm_ctx.ctx; - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"abcd", 4, 1234, 0); - - if (trie_ctx->root.nc['a'] != NULL && - trie_ctx->root.nc['a']->nc['b'] != NULL && - trie_ctx->root.nc['a']->nc['b']->nc['c'] != NULL && - trie_ctx->root.nc['a']->nc['b']->nc['c']->nc['d'] != NULL) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestInitAddPattern07 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - - MpmInitCtx(&mpm_ctx, MPM_TRIE); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"abcd", 4, 1234, 0); - - if (mpm_ctx.max_pattern_id == 1234) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch01 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"abcd", 4, 0, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - - u_int32_t cnt = TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"abcd", 4); - MpmMatchCleanup(&mpm_thread_ctx); - - if (cnt == 1) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch02 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"abcd", 4, 0, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - - u_int32_t cnt = TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"abce", 4); - MpmMatchCleanup(&mpm_thread_ctx); - - if (cnt == 0) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch03 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"abcd", 4, 0, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - - u_int32_t cnt = TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"abcdefgh", 8); - MpmMatchCleanup(&mpm_thread_ctx); - - if (cnt == 1) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch04 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"bcde", 4, 0, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - - u_int32_t cnt = TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"abcdefgh", 8); - MpmMatchCleanup(&mpm_thread_ctx); - - if (cnt == 1) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch05 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"efgh", 4, 0, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - - u_int32_t cnt = TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"abcdefgh", 8); - MpmMatchCleanup(&mpm_thread_ctx); - - if (cnt == 1) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch06 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPatternNocase(&mpm_ctx, (u_int8_t *)"eFgH", 4, 0, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - - u_int32_t cnt = TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"abcdEfGh", 8); - MpmMatchCleanup(&mpm_thread_ctx); - - if (cnt == 1) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch07 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPatternNocase(&mpm_ctx, (u_int8_t *)"abcd", 4, 0, 0); - TrieAddPatternNocase(&mpm_ctx, (u_int8_t *)"eFgH", 4, 1, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 2); - - u_int32_t cnt = TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"abcdEfGh", 8); - MpmMatchCleanup(&mpm_thread_ctx); - - if (cnt == 2) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch08 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"abcde", 5, 0, 0); - TrieAddPattern(&mpm_ctx, (u_int8_t *)"bcde", 4, 1, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 2); - - u_int32_t cnt = TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"abcdefgh", 8); - MpmMatchCleanup(&mpm_thread_ctx); - - if (cnt == 2) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch09 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"ab", 2, 0, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - - u_int32_t cnt = TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"ab", 2); - MpmMatchCleanup(&mpm_thread_ctx); - - if (cnt == 1) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch10 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"bc", 2, 0, 0); - TrieAddPattern(&mpm_ctx, (u_int8_t *)"gh", 2, 1, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 2); - - u_int32_t cnt = TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"abcdefgh", 8); - MpmMatchCleanup(&mpm_thread_ctx); - - if (cnt == 2) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch11 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"a", 1, 0, 0); - TrieAddPattern(&mpm_ctx, (u_int8_t *)"d", 1, 1, 0); - TrieAddPattern(&mpm_ctx, (u_int8_t *)"h", 1, 2, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 3); - - u_int32_t cnt = TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"abcdefgh", 8); - MpmMatchCleanup(&mpm_thread_ctx); - - if (cnt == 3) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch12 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPatternNocase(&mpm_ctx, (u_int8_t *)"A", 1, 0, 0); - TrieAddPattern(&mpm_ctx, (u_int8_t *)"d", 1, 1, 0); - TrieAddPattern(&mpm_ctx, (u_int8_t *)"Z", 1, 2, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 2); - - u_int32_t cnt = TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"abcdefgh", 8); - MpmMatchCleanup(&mpm_thread_ctx); - - if (cnt == 2) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch13 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"a", 1, 0, 0); - TrieAddPattern(&mpm_ctx, (u_int8_t *)"de",2, 1, 0); - TrieAddPattern(&mpm_ctx, (u_int8_t *)"h", 1, 2, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 3); - - u_int32_t cnt = TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"abcdefgh", 8); - MpmMatchCleanup(&mpm_thread_ctx); - - if (cnt == 3) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch14 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPatternNocase(&mpm_ctx, (u_int8_t *)"A", 1, 0, 0); - TrieAddPattern(&mpm_ctx, (u_int8_t *)"de",2, 1, 0); - TrieAddPattern(&mpm_ctx, (u_int8_t *)"Z", 1, 2, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 2); - - u_int32_t cnt = TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"abcdefgh", 8); - MpmMatchCleanup(&mpm_thread_ctx); - - if (cnt == 2) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch15 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPattern(&mpm_ctx, (u_int8_t *)"A", 1, 0, 0); - TrieAddPattern(&mpm_ctx, (u_int8_t *)"de",2, 1, 0); - TrieAddPattern(&mpm_ctx, (u_int8_t *)"Z", 1, 2, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 3); - - TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"abcdefgh", 8); - - u_int32_t len = mpm_thread_ctx.match[1].len; - - MpmMatchCleanup(&mpm_thread_ctx); - - if (len == 1) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -int TrieTestSearch16 (void) { - int result = 0; - MpmCtx mpm_ctx; - MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_TRIE); - - TrieAddPatternNocase(&mpm_ctx, (u_int8_t *)"A", 1, 0, 0); - TrieAddPattern(&mpm_ctx, (u_int8_t *)"de",2, 1, 0); - TrieAddPattern(&mpm_ctx, (u_int8_t *)"Z", 1, 2, 0); - TrieThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 2); - - TrieSearch(&mpm_ctx, &mpm_thread_ctx, NULL, (u_int8_t *)"abcdefgh", 8); - - u_int32_t len = mpm_thread_ctx.match[0].len; - - MpmMatchCleanup(&mpm_thread_ctx); - - if (len == 1) - result = 1; - - TrieThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - TrieDestroyCtx(&mpm_ctx); - return result; -} - -void TrieRegisterTests(void) { - UtRegisterTest("TrieTestInitCtx01", TrieTestInitCtx01, 1); - UtRegisterTest("TrieTestInitCtx02", TrieTestInitCtx02, 1); - UtRegisterTest("TrieTestInitCtx03", TrieTestInitCtx03, 1); - - UtRegisterTest("TrieTestThreadInitCtx01", TrieTestThreadInitCtx01, 1); - UtRegisterTest("TrieTestThreadInitCtx02", TrieTestThreadInitCtx02, 1); - - UtRegisterTest("TrieTestInitAddPattern01", TrieTestInitAddPattern01, 1); - UtRegisterTest("TrieTestInitAddPattern02", TrieTestInitAddPattern02, 1); - UtRegisterTest("TrieTestInitAddPattern03", TrieTestInitAddPattern03, 1); - UtRegisterTest("TrieTestInitAddPattern04", TrieTestInitAddPattern04, 1); - UtRegisterTest("TrieTestInitAddPattern05", TrieTestInitAddPattern05, 1); - UtRegisterTest("TrieTestInitAddPattern06", TrieTestInitAddPattern06, 1); - UtRegisterTest("TrieTestInitAddPattern07", TrieTestInitAddPattern07, 1); - - UtRegisterTest("TrieTestSearch01", TrieTestSearch01, 1); - UtRegisterTest("TrieTestSearch02", TrieTestSearch02, 1); - UtRegisterTest("TrieTestSearch03", TrieTestSearch03, 1); - UtRegisterTest("TrieTestSearch04", TrieTestSearch04, 1); - UtRegisterTest("TrieTestSearch05", TrieTestSearch05, 1); - UtRegisterTest("TrieTestSearch06", TrieTestSearch06, 1); - UtRegisterTest("TrieTestSearch07", TrieTestSearch07, 1); - UtRegisterTest("TrieTestSearch08", TrieTestSearch08, 1); - UtRegisterTest("TrieTestSearch09", TrieTestSearch09, 1); - UtRegisterTest("TrieTestSearch10", TrieTestSearch10, 1); - UtRegisterTest("TrieTestSearch11", TrieTestSearch11, 1); - UtRegisterTest("TrieTestSearch12", TrieTestSearch12, 1); - UtRegisterTest("TrieTestSearch13", TrieTestSearch13, 1); - UtRegisterTest("TrieTestSearch14", TrieTestSearch14, 1); - UtRegisterTest("TrieTestSearch15", TrieTestSearch15, 1); - UtRegisterTest("TrieTestSearch16", TrieTestSearch16, 1); -} -#endif diff --git a/src/util-mpm-trie.h b/src/util-mpm-trie.h deleted file mode 100644 index 9d84883d85..0000000000 --- a/src/util-mpm-trie.h +++ /dev/null @@ -1,86 +0,0 @@ -/* Copyright (c) 2008 Victor Julien */ - -#ifndef __UTIL_MPM_TRIE_H__ -#define __UTIL_MPM_TRIE_H__ - -//#define MPM_DBG_PERF - -#define MPM_ENDMATCH_SINGLE 0x01 /* A single match is sufficient */ -#define MPM_ENDMATCH_OFFSET 0x02 /* has offset setting */ -#define MPM_ENDMATCH_DEPTH 0x04 /* has depth setting */ - -typedef struct _TrieCharacter { - u_int16_t min_matchlen_left; /* minimum match length left from this - * character. Used for determining if this - * leaf can match at all */ - struct _TrieCharacter *nc[256]; - MpmEndMatch *em; -} TrieCharacter; - -typedef struct _TriePartialMatch { - struct _TriePartialMatch *prev; - struct _TriePartialMatch *next; - TrieCharacter *c; -} TriePartialMatch; - -typedef struct _TriePartialMatchList { - TriePartialMatch *top; -} TriePartialMatchList; - -/* global ctx */ -typedef struct _TrieCtx { - u_int32_t queuelen; - u_int32_t max_queuelen; - - u_int32_t keywords; - u_int32_t nocase_keywords; - u_int32_t characters; - - TrieCharacter root; - TrieCharacter nocase_root; -} TrieCtx; - -/* thread ctx */ -typedef struct _TrieThreadCtx { -#ifdef MPM_DBG_PERF - /* debug/performance counters */ - u_int64_t mpmsearch; - u_int64_t mpmsearchoffsetdepth; - - u_int64_t searchchar_cnt; - u_int64_t searchchar_pmloop_cnt; - u_int64_t searchchar_nocase_cnt; - u_int64_t searchchar_nocase_pmloop_cnt; - - u_int64_t searchchar_nocase_matchroot_cnt; - u_int64_t searchchar_nocase_prepeek_cnt; - u_int64_t searchchar_nocase_prepeekmatch_cnt; - u_int64_t searchchar_nocase_prepeek_nomatchnobuf_cnt; - u_int64_t searchchar_nocase_prepeek_nomatchbuflen_cnt; - u_int64_t searchchar_nocase_pmcreate_cnt; - - u_int64_t searchchar_matchroot_cnt; - u_int64_t searchchar_prepeek_cnt; - u_int64_t searchchar_prepeekmatch_cnt; - u_int64_t searchchar_prepeek_nomatchnobuf_cnt; - u_int64_t searchchar_prepeek_nomatchbuflen_cnt; - u_int64_t searchchar_pmcreate_cnt; -#endif /* MPM_DBG_PERF */ - - /* workspace for partial matches in TrieSearch */ - TriePartialMatchList spare_queue; - TriePartialMatch *pmqueue; - TriePartialMatch *nocase_pmqueue; - - u_int8_t *buf; - u_int8_t *bufmin; - u_int8_t *bufmax; - u_int8_t *buflast; - -} TrieThreadCtx; - -/* prototypes */ -void MpmTrieRegister(void); - -#endif /* __UTIL_MPM_TRIE_H__ */ - diff --git a/src/util-mpm-wumanber.h b/src/util-mpm-wumanber.h index 6474b981b0..aee6c4dbbc 100644 --- a/src/util-mpm-wumanber.h +++ b/src/util-mpm-wumanber.h @@ -13,24 +13,24 @@ //#define WUMANBER_COUNTERS -typedef struct _WmPattern { +typedef struct WmPattern_ { u_int8_t *cs; /* case sensitive */ u_int8_t *ci; /* case INsensitive */ u_int16_t len; - struct _WmPattern *next; + struct WmPattern_ *next; u_int16_t prefix_ci; u_int16_t prefix_cs; u_int8_t flags; MpmEndMatch *em; } WmPattern; -typedef struct _WmHashItem_ { +typedef struct WmHashItem_ { u_int8_t flags; u_int16_t idx; - struct _WmHashItem_ *nxt; + struct WmHashItem_ *nxt; } WmHashItem; -typedef struct _WmCtx { +typedef struct WmCtx_ { /* hash used during ctx initialization */ WmPattern **init_hash; @@ -49,9 +49,9 @@ typedef struct _WmCtx { WmHashItem search_hash1[256]; /* we store our own multi byte scan ptr here for WmSearch1 */ - u_int32_t (*MBScan)(struct _MpmCtx *, struct _MpmThreadCtx *, PatternMatcherQueue *, u_int8_t *, u_int16_t); + u_int32_t (*MBScan)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, u_int8_t *, u_int16_t); /* we store our own multi byte search ptr here for WmSearch1 */ - u_int32_t (*MBSearch)(struct _MpmCtx *, struct _MpmThreadCtx *, PatternMatcherQueue *, u_int8_t *, u_int16_t); + u_int32_t (*MBSearch)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, u_int8_t *, u_int16_t); /* pattern arrays */ WmPattern **parray; @@ -61,7 +61,7 @@ typedef struct _WmCtx { u_int16_t *search_shifttable; } WmCtx; -typedef struct _WmThreadCtx { +typedef struct WmThreadCtx_ { #ifdef WUMANBER_COUNTERS u_int32_t scan_stat_pminlen_calls; u_int32_t scan_stat_pminlen_total; diff --git a/src/util-mpm.c b/src/util-mpm.c index c583c5915f..d3fda518df 100644 --- a/src/util-mpm.c +++ b/src/util-mpm.c @@ -8,7 +8,6 @@ #include "util-mpm.h" /* include pattern matchers */ -#include "util-mpm-trie.h" #include "util-mpm-wumanber.h" #include "util-mpm-b2g.h" #include "util-mpm-b3g.h" @@ -226,7 +225,6 @@ void MpmInitCtx (MpmCtx *mpm_ctx, u_int16_t matcher) { void MpmTableSetup(void) { memset(mpm_table, 0, sizeof(mpm_table)); - //MpmTrieRegister(); MpmWuManberRegister(); MpmB2gRegister(); MpmB3gRegister(); diff --git a/src/util-mpm.h b/src/util-mpm.h index 3577b81de1..8d2eb285b2 100644 --- a/src/util-mpm.h +++ b/src/util-mpm.h @@ -9,7 +9,6 @@ #define MPM_ENDMATCH_NOSEARCH 0x08 /* if this matches, no search is required (for this pattern) */ enum { - MPM_TRIE, MPM_WUMANBER, MPM_B2G, MPM_B3G, @@ -19,31 +18,31 @@ enum { }; /* Data structures */ -typedef struct _MpmEndMatch { +typedef struct MpmEndMatch_ { u_int32_t id; u_int16_t depth; u_int16_t offset; u_int8_t flags; - struct _MpmEndMatch *next; + struct MpmEndMatch_ *next; u_int32_t sig_id; /* sig callback stuff -- internal id */ } MpmEndMatch; -typedef struct _MpmMatch { +typedef struct MpmMatch_ { u_int16_t offset; /* offset of this match in the search buffer */ - struct _MpmMatch *next; /* match list -- used to connect a match to a + struct MpmMatch_ *next; /* match list -- used to connect a match to a * pattern id. */ - struct _MpmMatch *qnext; /* queue list -- used to cleanup all matches after + struct MpmMatch_ *qnext; /* queue list -- used to cleanup all matches after * the inspection. */ - struct _MpmMatchBucket *mb; /* pointer back to the bucket */ + struct MpmMatchBucket_ *mb; /* pointer back to the bucket */ } MpmMatch; -typedef struct _MpmMatchBucket { +typedef struct MpmMatchBucket_ { MpmMatch *top; MpmMatch *bot; u_int32_t len; } MpmMatchBucket; -typedef struct _MpmThreadCtx { +typedef struct MpmThreadCtx_ { void *ctx; u_int32_t memory_cnt; @@ -65,7 +64,7 @@ typedef struct _MpmThreadCtx { /* helper structure for the detection engine. The Pattern Matcher thread * has this and passes a pointer to it to the pattern matcher. The actual * pattern matcher will fill the structure. */ -typedef struct _PatternMatcherQueue { +typedef struct PatternMatcherQueue_ { /* sig callback stuff XXX consider a separate struct for this*/ u_int32_t *sig_id_array; /* array with internal sig id's that had a pattern match. These will be inspected @@ -77,23 +76,23 @@ typedef struct _PatternMatcherQueue { require a search-followup */ } PatternMatcherQueue; -typedef struct _MpmCtx { +typedef struct MpmCtx_ { void *ctx; - void (*InitCtx)(struct _MpmCtx *); - void (*InitThreadCtx)(struct _MpmCtx *, struct _MpmThreadCtx *, u_int32_t); - void (*DestroyCtx)(struct _MpmCtx *); - void (*DestroyThreadCtx)(struct _MpmCtx *, struct _MpmThreadCtx *); - int (*AddScanPattern)(struct _MpmCtx *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t, u_int8_t); - int (*AddScanPatternNocase)(struct _MpmCtx *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t, u_int8_t); - int (*AddPattern)(struct _MpmCtx *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t); - int (*AddPatternNocase)(struct _MpmCtx *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t); - int (*Prepare)(struct _MpmCtx *); - u_int32_t (*Scan)(struct _MpmCtx *, struct _MpmThreadCtx *, PatternMatcherQueue *, u_int8_t *, u_int16_t); - u_int32_t (*Search)(struct _MpmCtx *, struct _MpmThreadCtx *, PatternMatcherQueue *, u_int8_t *, u_int16_t); - void (*Cleanup)(struct _MpmThreadCtx *); - void (*PrintCtx)(struct _MpmCtx *); - void (*PrintThreadCtx)(struct _MpmThreadCtx *); + void (*InitCtx)(struct MpmCtx_ *); + void (*InitThreadCtx)(struct MpmCtx_ *, struct MpmThreadCtx_ *, u_int32_t); + void (*DestroyCtx)(struct MpmCtx_ *); + void (*DestroyThreadCtx)(struct MpmCtx_ *, struct MpmThreadCtx_ *); + int (*AddScanPattern)(struct MpmCtx_ *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t, u_int8_t); + int (*AddScanPatternNocase)(struct MpmCtx_ *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t, u_int8_t); + int (*AddPattern)(struct MpmCtx_ *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t); + int (*AddPatternNocase)(struct MpmCtx_ *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t); + int (*Prepare)(struct MpmCtx_ *); + u_int32_t (*Scan)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, u_int8_t *, u_int16_t); + u_int32_t (*Search)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, u_int8_t *, u_int16_t); + void (*Cleanup)(struct MpmThreadCtx_ *); + void (*PrintCtx)(struct MpmCtx_ *); + void (*PrintThreadCtx)(struct MpmThreadCtx_ *); u_int32_t memory_cnt; u_int32_t memory_size; @@ -115,22 +114,22 @@ typedef struct _MpmCtx { } MpmCtx; -typedef struct MpmTableElmt { +typedef struct MpmTableElmt_ { char *name; - void (*InitCtx)(struct _MpmCtx *); - void (*InitThreadCtx)(struct _MpmCtx *, struct _MpmThreadCtx *, u_int32_t); - void (*DestroyCtx)(struct _MpmCtx *); - void (*DestroyThreadCtx)(struct _MpmCtx *, struct _MpmThreadCtx *); - int (*AddScanPattern)(struct _MpmCtx *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t, u_int8_t); - int (*AddScanPatternNocase)(struct _MpmCtx *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t, u_int8_t); - int (*AddPattern)(struct _MpmCtx *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t); - int (*AddPatternNocase)(struct _MpmCtx *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t); - int (*Prepare)(struct _MpmCtx *); - u_int32_t (*Scan)(struct _MpmCtx *, struct _MpmThreadCtx *, PatternMatcherQueue *, u_int8_t *, u_int16_t); - u_int32_t (*Search)(struct _MpmCtx *, struct _MpmThreadCtx *, PatternMatcherQueue *, u_int8_t *, u_int16_t); - void (*Cleanup)(struct _MpmThreadCtx *); - void (*PrintCtx)(struct _MpmCtx *); - void (*PrintThreadCtx)(struct _MpmThreadCtx *); + void (*InitCtx)(struct MpmCtx_ *); + void (*InitThreadCtx)(struct MpmCtx_ *, struct MpmThreadCtx_ *, u_int32_t); + void (*DestroyCtx)(struct MpmCtx_ *); + void (*DestroyThreadCtx)(struct MpmCtx_ *, struct MpmThreadCtx_ *); + int (*AddScanPattern)(struct MpmCtx_ *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t, u_int8_t); + int (*AddScanPatternNocase)(struct MpmCtx_ *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t, u_int8_t); + int (*AddPattern)(struct MpmCtx_ *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t); + int (*AddPatternNocase)(struct MpmCtx_ *, u_int8_t *, u_int16_t, u_int16_t, u_int16_t, u_int32_t, u_int32_t); + int (*Prepare)(struct MpmCtx_ *); + u_int32_t (*Scan)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, u_int8_t *, u_int16_t); + u_int32_t (*Search)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, u_int8_t *, u_int16_t); + void (*Cleanup)(struct MpmThreadCtx_ *); + void (*PrintCtx)(struct MpmCtx_ *); + void (*PrintThreadCtx)(struct MpmThreadCtx_ *); void (*RegisterUnittests)(void); u_int8_t flags; } MpmTableElmt; diff --git a/src/util-pool.h b/src/util-pool.h index 3dac1d399e..4bf463afb5 100644 --- a/src/util-pool.h +++ b/src/util-pool.h @@ -4,13 +4,13 @@ #define __UTIL_POOL_H__ /* pool bucket structure */ -typedef struct _PoolBucket { +typedef struct PoolBucket_ { void *data; - struct _PoolBucket *next; + struct PoolBucket_ *next; } PoolBucket; /* pool structure */ -typedef struct _Pool { +typedef struct Pool_ { u_int32_t max_buckets; u_int32_t allocated; diff --git a/src/util-unittest.c b/src/util-unittest.c index 8fd7290f5e..4dba9197c9 100644 --- a/src/util-unittest.c +++ b/src/util-unittest.c @@ -33,13 +33,13 @@ static int UtAppendTest(UtTest **list, UtTest *test) { return 0; } -void UtRegisterTest(char *name, int(*testfn)(void), int evalue) { +void UtRegisterTest(char *name, int(*TestFn)(void), int evalue) { UtTest *ut = UtAllocTest(); if (ut == NULL) return; ut->name = name; - ut->testfn = testfn; + ut->TestFn = TestFn; ut->evalue = evalue; ut->next = NULL; @@ -55,7 +55,7 @@ int UtRunTests(void) { for (ut = ut_list; ut != NULL; ut = ut->next) { printf("Test %-60s : ", ut->name); fflush(stdout); /* flush so in case of a segv we see the testname */ - int ret = ut->testfn(); + int ret = ut->TestFn(); printf("%s\n", (ret == ut->evalue) ? "pass" : "FAILED"); if (ret != ut->evalue) { result = 1; diff --git a/src/util-unittest.h b/src/util-unittest.h index 19cb92a7b3..60f845a7eb 100644 --- a/src/util-unittest.h +++ b/src/util-unittest.h @@ -3,18 +3,18 @@ #ifndef __UTIL_UNITTEST_H__ #define __UTIL_UNITTEST_H__ -typedef struct _UtTest { +typedef struct UtTest_ { char *name; - int(*testfn)(void); + int(*TestFn)(void); int evalue; - struct _UtTest *next; + struct UtTest_ *next; } UtTest; -void UtRegisterTest(char *name, int(*testfn)(void), int evalue); +void UtRegisterTest(char *name, int(*TestFn)(void), int evalue); int UtRunTests(void); void UtInitialize(void); void UtCleanup(void); diff --git a/src/util-var-name.c b/src/util-var-name.c index 07570632d0..8bffae7444 100644 --- a/src/util-var-name.c +++ b/src/util-var-name.c @@ -2,7 +2,7 @@ #include "detect.h" #include "util-hashlist.h" -typedef struct _VariableName { +typedef struct VariableName_ { char *name; u_int8_t type; /* flowbit, pktvar, etc */ u_int16_t idx; diff --git a/src/util-var.h b/src/util-var.h index e9e3821af6..0344c2b6ca 100644 --- a/src/util-var.h +++ b/src/util-var.h @@ -1,10 +1,10 @@ #ifndef __UTIL_VAR_H__ #define __UTIL_VAR_H__ -typedef struct _GenericVar { +typedef struct GenericVar_ { u_int8_t type; u_int16_t idx; - struct _GenericVar *next; + struct GenericVar_ *next; } GenericVar; void GenericVarFree(GenericVar *);