Commit Graph

4221 Commits (1cbd1cdf362ce1644bf40a109ff6955df5af08c6)

Author SHA1 Message Date
Victor Julien 4165bf8951 log-http: enforce hostname print limit 11 years ago
Victor Julien 1476db44d9 Convert Flow macros to inline functions
Convert FlowReference and FlowDeReference to inline functions for
better readability and to aid static code analyzers.
11 years ago
Victor Julien b4e6bbe4bc flowvar: initialize new memory to prevent issues on error handling 11 years ago
Victor Julien 0beb7ed781 pcap: fix stats dump logic
pcap has a callback function that is called for each packet. Once a
second, it's meant to 'dump stats'. However, the timing logic was
broken, so it would actually dump stats for each packet.

By moving the stats second timer into the thread vars, next calls of
the callback will be able to use the stored time.
11 years ago
Victor Julien 9e85b8d35e flow timeout: remove now unused code 11 years ago
Victor Julien 85b1a8ff26 flow: fix typo in function name
FlowForceReassemblyNeedReassmbly -> FlowForceReassemblyNeedReassembly
11 years ago
Victor Julien 3b3dce8328 flow timeout cleanup and fix
Flow timeout code worked by luck when checking if a flow still needed
reassembly for app layer inspection or logging. It would check for a
part of raw reassembly (smsg list) to determine if detection was
needed. In this case it would also process app layer cleanup,
including logging.

Introduced AppLayerTransactionGetActive which returns the lowest tx_id
in a direction that still needs some work.

FlowForceReassemblyNeedReassmbly now uses it to determine if the
applayer still needs work.

Converted FlowForceReassemblyForHash to use the checking function
FlowForceReassemblyNeedReassmbly as well, so that checking if a flow
needs work is now unified.
11 years ago
Victor Julien b32abea06b flow/stream: use named values in flow timeout code 11 years ago
Victor Julien 8522da8ea5 stream: add option to disable raw reassembly
Raw reassembly is used only by the detection engine. For users only
caring about logging it's a significant overhead, both in cpu and
memory usage.

The option is called 'raw' and lives under the stream.reassembly
options.

stream:
  memcap: 32mb
  checksum-validation: yes      # reject wrong csums
  inline: auto                  # auto will use inline mode in IPS mode, yes or no set it statically
  reassembly:
    memcap: 64mb
    depth: 1mb                  # reassemble 1mb into a stream
    toserver-chunk-size: 2560
    toclient-chunk-size: 2560
    randomize-chunk-size: yes
    #randomize-chunk-range: 10
    raw: false # <- new option
11 years ago
Eric Leblond 47b5fc0934 erf-dag: fix typo in header guard
Spotted out by clang:
 source-erf-dag.h|25 col 9| warning: '__SOURCE_ERR_DAG_H__'
 is used as a header guard here, followed by #define of a different macro
 [-Wheader-guard]
11 years ago
Jason Ish eaff01a57f Use the stack for temporary memory buffers. 11 years ago
Jason Ish ab7091927e When setting final configuration nodes, set the whole tree as final.
Prevents benign log message of parent nodes of final values being
redefined (which ends up having no affect as the final nodes
are protected from being removed).
11 years ago
Eric Leblond 729540673e htp: display info about randomization
When randomizatin is used display a message about actual values.
11 years ago
Eric Leblond ff784075a2 htp: randomization of htp inspection sizes
This is an implementation of #940. It randomize libhtp request
and response size if the same way this has been done for stream
inspection.
11 years ago
Victor Julien 81ee6f5aad lua: push correct length back through ScFlowvarGet, work around valgrind warning 11 years ago
Victor Julien 86b299d06c lua: clear stack after each script run 11 years ago
Victor Julien ae69a4a024 luajit: pass calling rule's sid,gid,rev to script as SCRuleSid, SCRuleGid, SCRuleRev. 11 years ago
Eric Leblond f76448c1e6 decode: fix failure in layered tunnel
If we have multiple layer of tunnel, the decoding of initial
Packet will recurse in DecodeTunnel function called in
PacketTunnelPktSetup. If we are not setting the pseudo
packet root before calling DecodeTunnel (as done in previous
code), then the tunnel root will no be correct for the lower
layer packets. This result in an counter problem and a suricata
failure after some time.
11 years ago
Jason Ish e9a4871077 Fix alignment in usage. 11 years ago
Giuseppe Longo ae9393987e Adds a defrag configuration example in suricata.yaml 11 years ago
Victor Julien 0a24ac0855 Fix Conf api usage after rebase 11 years ago
Jason Ish 8d29dfca59 Instead of exiting on memory failure, log a warning then return NULL
to signify an error to the caller.
11 years ago
Jason Ish 5f6705c4dc Better document ConfSet and ConfSetFinal. 11 years ago
Jason Ish b033acfb0c Subsequent configuration keys now override previous ones
instead of merging.

The exception is final values, for example, values like
default-log-dir that may be set on the command line.
11 years ago
Jason Ish c981a16579 Function to prune all non-final nodes from a configuration node. 11 years ago
Jason Ish b8e13d4bd6 More concise API for setting config values that
can be overrided or not (final values).
11 years ago
Jason Ish 0820ac9355 Cleanup ConfSet, ConfGet, make more concise.
Removes ifdef's for readability by using strchr instead
of strtok.
11 years ago
Victor Julien 6cd6caf3ea tls: allow matching for @ symbol in tls.subject
Also in tls.issuerdn keyword.

Original patch by Chris Wakelin.

Fixes #1042.
11 years ago
Anoop Saldanha 6ea8ac44ff FTP parser updated to not use the archaic App layer feature of AppLayerParserResultElmt.
The parser otherwise remains pretty much the same.
11 years ago
Anoop Saldanha 80c08f8642 Updated the ftp response handler to return without doing anything.
Currently the processing happening inside the handler is not being used
anywhere else in the engine.
11 years ago
Anoop Saldanha 8523cbadcf Restructured flow_proto mapping enums.
Moved FLOW_PROTO_DEFAULT down the enum list.
11 years ago
Anoop Saldanha a49cbf8a49 Code cleanup.
Use the MpmAddPattern[CS|CI] wrapper to add patterns to the mpm context.

Also use MpmInitCtx() to init the mpm context.
11 years ago
Anoop Saldanha 9c0456ebbe Removed unused function MpmMatcherGetMaxPatternLength. 11 years ago
Victor Julien cc61a190ce Reduce allocs in boyer moore prepare phase 11 years ago
Victor Julien 8344854a1f Don't alloc for hash lookup in SCClassConfGetClasstype 11 years ago
Victor Julien f04618c7ad Don't malloc temp var in SCRuleVarsGetConfVar 11 years ago
Victor Julien 941d5a1081 Don't use strdup in ip-only address parsing 11 years ago
Victor Julien a7a77e32ca Convert classtype keyword to pcre_copy_substring 11 years ago
Victor Julien 4dd605ae3b Convert reference keyword to pcre_copy_substring 11 years ago
Victor Julien 3f8947ff3d app layer: set event if proto detect disabled for a stream, but we see data anyway. 11 years ago
Victor Julien 7074ca373b proto detection: add limit for one sided sessions
If a session only has data in one direction, like ftp data sessions,
protocol detection will only run in one direction. This led to a
situation where reassembly would hold all the segments as proto
detection was never flagged as complete.

This patch introduces a limit for protocol detection in this case.
If the limit is reached, detection will give up.
11 years ago
Victor Julien abccbe13f3 stream: add size debug code 11 years ago
Victor Julien daedb6c557 stream: wait for protocol detection to complete
Wait for protocol detection to complete before removing segments
from the list.
11 years ago
Eric Leblond 0460b194b1 decode: clean DecodeThreadVars counter
Speed counters are not compute anymore and can be removed from the
structure definition.
11 years ago
Eric Leblond 1bdc39fe9b cmdline: add -k to specify checksum validation
This patch adds a '-k' option to suricata to be able to specify
the checksum validation to use. If '-k all' is used, checksum
validation is forced. If '-k none' is used, no checksum validation
is made.

Message output in case of detection of a pcap file with a probable
cheksum issue has been updated to indicate that '-k' is a solution.
11 years ago
Eric Leblond 8b5be26f49 pcap-file: add checksum-checks configuration variable
This patch adds support for checksum-checks in the pcap-file running
mode. This is the same functionnality as the one already existing for
live interface.

It can be setup in the YAML:
  pcap-file:
    checksum-checks: auto

A message is displayed for small pcap to warn that invalid checksum
rate is big on the pcap file and that checksum-check could
be set to no.
11 years ago
Eric Leblond b2c58b8d14 Set packet invalid flag during decoding.
This patch set a new value in pkt->flag to signal that a packet is
invalid during decoding. The patch has been obtained via a coccinelle
transformation.
11 years ago
Eric Leblond 3088b6ac34 Add invalid pkt counter.
This patch adds and increments a invalid packet counter. It
does this by introducing PacketDecodeFinalize function

This function is incrementing the invalid counter and is also
signalling the packet to CUDA.
11 years ago
Victor Julien 92568c3857 Fix parsing of 'custom' detect grouping values
Also, add error checking

Bug 892
11 years ago
Victor Julien ffe4a302a1 vars: optimize layout to reduce size requirements of flowbits and other vars 11 years ago
Victor Julien 3e604b8703 pcre: parsing cleanup
Remove all flags indicating the buffer type. They were only used
at parse time.

Because of this the DetectPcreData_ structure could shrink to 32
bytes.
11 years ago
Victor Julien ab22385083 stream: minor clean up of TcpSession structure 11 years ago
Victor Julien 866b3a1c5d content: reorder DetectContentData member, shrinking the struct from 64 to 48 bytes. 11 years ago
Victor Julien 277fb61c1d defrag: clean up
Rename PacketDefragPktFinishSetup to PacketDefragPktSetupParent to
better refect it's function.
11 years ago
Eric Leblond 3fdf52239d defrag: don't modify packet if defrag fails
If defrag fails dur to an invalid decoding, we are not modifying
the origin packet anymore.
11 years ago
Eric Leblond c611b258a5 decode: PacketTunnelPktSetup replaces PacketPseudoPktSetup
This patch replaces PacketPseudoPktSetup by a better named
PacketTunnelPktSetup function which is also in charge of doing
the decoding of the tunneled packet.
This allow to clean the code. But it also fixes an issue.
Previously, if the DecodeTunnel function was failling (cause of
an invalid packet mainly), the result was that the original packet
to be considered as a tunnel packet (and not inspected by payload
detection).
11 years ago
Eric Leblond d4b7ecfbe3 decode: update API to return error
In some cases, the decoding is not possible and some really invalid
packet can be created. This is in particular the case of tunnel. In
that case, it is more interesting to forget about the tunneled
packet and only consider the original packet.

DecodeTunnel function is maked as warn_unused_result because it is
meaningful for the decoder to know if the underlying data were not
correct. And in this case, only focus detection on the content.
11 years ago
Victor Julien 0b0e9340dc rule setup: cleanup
Remove rule preparation logic that ran, but it's results were not
used.
11 years ago
Victor Julien 2be6829986 Convert dsize keyword parsing to use pcre_copy_substring 11 years ago
Victor Julien dcc75acdec Convert pcre keyword parsing to use pcre_copy_substring 11 years ago
Victor Julien 1f69da80bf rule parser: convert to use pcre_copy_string 11 years ago
Victor Julien d397ed94c5 detect: use macro for max rule size 11 years ago
Victor Julien 9d35855a95 Convert flowbits keyword parsing to use pcre_copy_substring 11 years ago
Victor Julien beab8d401c Convert flow keyword parsing to use pcre_copy_substring 11 years ago
Victor Julien 223fedb8fe Convert ParseSizeString to use pcre_copy_substring 11 years ago
Victor Julien 3f4ce6dadd rule parser: don't use uninitialized value 11 years ago
Giuseppe Longo f03278d132 feature #417: add support for configuration per host timeout value 11 years ago
Victor Julien 54610cb4a4 rule parsing cleanups
Clean up usage of array of pointers to the various parts of a rule.
11 years ago
Victor Julien 67989e7e4e rule parsing: reduce mallocs and clean up
Reduce mallocs during rule parsing. Also, no longer recursively
call the option parse function.
11 years ago
Victor Julien 2ce8895f0a address and port: reduce memory allocs 11 years ago
Jason Ish 06f4fe8e0c Remove the single line if statements. 11 years ago
Jason Ish 8625c9eba8 Support for configuration include files. 11 years ago
Victor Julien e7f6107e79 signature address parsing improvements and tests
Fix sigatures not supporting [10.0.0.0/24, !10.1.1.1] notation when
used directly in a rule instead of through a variable.

Add tests for Bugs #815 and #920.
11 years ago
Victor Julien 3521c37d4a http: use body limit in inspection
When inspecting HTTP bodies there are several limits involved.
In this patch the reaching of the body limit will trigger body
inspection.

Without this, the body would only be inspected when inspection
limits "request-body-minimal-inspect-size" or
"response-body-minimal-inspect-size" were reached. If the body
limit was smaller than this value, the body would only be
inspected at the end of the tx or stream.
11 years ago
Victor Julien 493d531ae8 Fix using uninitialized memory (Bug #994) 11 years ago
Eric Leblond 9bbcc8671e util-ioctl: ioctl error should be a warning 11 years ago
Eric Leblond 286258df86 pcap: add warning about GRO and LRO usage
Use the new GetIfaceOffloading function to display a warning message
if pcap capture is used on Linux with GRO or LRO activated. This is
helpful for kernel after 2.6.31 were pcap will use mmaped capture.
TPACKET_V2 is used and this limit the size of the packet resulting
in truncated packets when merged packets are received.
11 years ago
Eric Leblond 2855ee5aef af-packet: add warning message if LRO or GRO are set
This patch query the network interface to detect if LRO or GRO are
used in mmap TPACKET_V2 mode.
11 years ago
Eric Leblond fcc8759561 util-ioctl: add GRO/LRO detection capabilities
This patch adds a new function GetIfaceOffloading which return 0
if LRO and GRO are not set on a interface and 1 if not the case.
11 years ago
Eric Leblond 008ed41cb4 util-ioctl: minor code cleaning.
Fix author e-mail and simplify an indentation.
11 years ago
Eric Leblond 853732210e pfring: improve error reporting at device opening
This patch improves the error message displayed if pfring_open fails.
11 years ago
Victor Julien 5330b1cae1 detect: don't consider smsgs for no inspect flag
When the PKT_NOPAYLOAD_INSPECTION flag is set, don't apply it to smsgs.
This way we can still inspect the outstanding smsgs.

The PKT_NOPAYLOAD_INSPECTION is set for encrypted traffic, and is combined
with disabling stream reassembly. So we only inspect the smsgs up to the
point of the disable detection point.
11 years ago
Victor Julien ab7677638e stream: improve raw reassembly
When checking the reassembly limit for raw reassembly, consider the
STREAMTCP_STREAM_FLAG_NOREASSEMBLY a trigger immediately. We won't
process any more segments in the reassembly engine anyway.
11 years ago
Victor Julien e392c0a4ce Fix autofp flow queue handler optimization 11 years ago
Victor Julien 480fddd189 build-info: add a nicer way of printing atomics support 11 years ago
Victor Julien ce120d4927 flow: aligned flow balance structures (used by autofp) to CLS to reduce false sharing 11 years ago
Victor Julien fb4967912c http: add meta-field-limit option
The meta-field-option allows for setting the hard limit of request
and response fields in HTTP. In requests this applies to the request
line and headers, not the body. In responses, this applies to the
response line and headers, not the body.

Libhtp uses a default limit of 18k. If this is reached an event is
raised.

Ticket 986.
11 years ago
Victor Julien 2ec57c36b4 SSE 4.2 memcmp: don't read beyond var boundary
In the SSE 4.2 SCMemcmpLowercase implementation, there would be a
_mm_load_si128 of a 2 byte array. However, _mm_load_si128 loads
16 bytes, causing it to read beyond the var. I don't think this lead
to crashes, as it was a static var, but clangs ASAN complained about
it.
11 years ago
Ken Steele d3c6913e28 Reduce the size of Packet structure
Share memory space for IPV4Vars and (IPV6Vars, IPV6ExtHdrs), since a
packet can only be either IPv4 or IPv6, but not both.

Share memory for TCPVars, UDPVars, ICMPV4Vars and ICMPV6Vars, since a
packet can only be only of these.

Then move other structure members around to remove holes reported by pahole.

This reduces the size of the Packet structure from 2944 bytes (46 cachelines)
down to 1976 (31 cachelines), a 33% reduction.
11 years ago
Victor Julien a8b971c710 http: strip 'proxy' part of http_uri
Strip the 'proxy' parts from the normalized uri as inspected by http_uri,
urilen, pcre /U and others.

  In a request line like:
    GET http://suricata-ids.org/blah/ HTTP/1.1
  the normalized URI will now be:
    /blah/

This doesn't affect http_raw_uri. So matching the hostname, etc is still
possible through this keyword.

Additionally, a new per HTTP 'personality' option was added to change
this behavior: "uri-include-all":

  uri-include-all: <true|false>
    Include all parts of the URI. By default the
    'scheme', username/password, hostname and port
    are excluded. Setting this option to true adds
    all of them to the normalized uri as inspected
    by http_uri, urilen, pcre with /U and the other
    keywords that inspect the normalized uri.
    Note that this does not affect http_raw_uri.

So adding uri-include-all:true to all personalities in the yaml will
restore the old default behavior.

Ticket 1008.
11 years ago
Ken Steele de6cbb01c8 Allocate mPIPE packet ingress queue in each worker thread.
Move the allocation of the mPipe ingress queue from a loop over
the number of workers in the main init function to being done inside
each worker thread. This allows allocating the memory locally on the
worker's CPU without needing to figure out ahead of time where that thread
will be running. This fixes one case of static mapping of workers to CPUs.

Use __thread to hold the queue rather than a global tables of queues.
11 years ago
Ken Steele 601c7c8e3c Cleanup Tile build for -Werror
Just the changes needed for the Tile architecture to compile cleanly with
-Werror.
11 years ago
Ken Steele f16b339fc4 Rename checksums to level3_comp_csum and level4_comp_csum.
This will also sharing even more memory in the Packet_ structure.
11 years ago
Eric Leblond 3dceca70ee suricata: move some code into PostConfLoadedSetup
All functions before daemonization are initialisation functions and thus the
call can be moved in PostConfLoadedSetup.
11 years ago
Victor Julien a84c502e50 Add SSE support to --build-info 11 years ago
Victor Julien 49a54713da memcmp: don't use SSE intrinsics if less that 16 bytes are available in SSE_4_2 version. 11 years ago
Victor Julien 8ffa30dd88 profiling: don't init rule profiling ctx if rule profiling is disabled 11 years ago
Victor Julien 660636c5bc profiling: when config is missing, keyword profiling is disabled 11 years ago
Victor Julien 2982408155 pcap: register counters for old pcap versions as well 11 years ago
Victor Julien 9a42f621f5 Fix pcre_study error check
pcre_study returning NULL is not necessarily an error, from the man page
pcre_study(3):

  "If the function returns NULL, either it could not find any additional
   information, or there was an error. You can tell the difference by
   looking at the error value. It is NULL in first case."

Older libpcre versions would return NULL, causing errors.
11 years ago