Commit graph

293 commits

Author SHA1 Message Date
Jon Siwek
455fc29b1a Migrate TypeList to store IntrusivePtrs
This changes return types of TypeList::Types() and
IndexType::IndexTypes() to return std::vector instead of type_list*
2020-05-14 17:18:00 -07:00
Tim Wojtulewicz
82978a8860 Merge remote-tracking branch 'origin/topic/jsiwek/fuzzing'
* origin/topic/jsiwek/fuzzing:
  Use zeek::detail namespace for fuzzer utils
  Set terminating flag during fuzzer cleanup
  Add missing include to standalone fuzzer driver
  Improve standalone fuzzer driver error messages
  Test fuzzers against seed corpus under CI ASan build
  Update fuzzing README with OSS-Fuzz integration notes
  Link fuzzers against shared library to reduce executable sizes
  Improve FuzzBuffer chunking
  Fix compiler warning in standalone fuzzer driver
  Adjust minor fuzzing documentation
  Exit immediately after running unit tests
  Add OSS-Fuzz Zeek script search path to fuzzers
  Assume libFuzzer when LIB_FUZZING_ENGINE file doesn't exist
  Change handling of LIB_FUZZING_ENGINE
  Change --enable-fuzzing to --enable-fuzzers
  Add standalone driver for fuzz targets
  Add basic structure for fuzzing targets
2020-05-12 18:53:06 -07:00
Jon Siwek
a08b1ff56f Add warning message for unknown Broker statuses
There's now a couple placeholder/unimplemented status values in Broker
related to upcoming routing features that we don't want to handle
explicitly for compatibility reasons, but also don't want the compiler
warning about unhandled values in the switch.
2020-04-29 15:28:18 -07:00
Jon Siwek
d533212a6a Merge branch 'master' into topic/jsiwek/fuzzing 2020-04-28 17:25:32 -07:00
Jon Siwek
8f1b34b915 Add basic structure for fuzzing targets
General changes:

* Add -D/--deterministic command line option as
  convenience/alternative to -G/--load-seeds (i.e. no file needed, it just
  uses zero-initialized random seeds).  It also changes Broker data
  stores over to using deterministic timing rather than real time.

* Add option to make Reporter abort on runtime scripting errors
2020-04-23 12:51:25 -07:00
Jon Siwek
094d6de979 Update all BIFs to return IntrusivePtr instead of Val* 2020-04-16 17:00:01 -07:00
Jon Siwek
d7be84de97 Update deprecated ValManager::GetPort usages 2020-04-16 16:47:19 -07:00
Tim Wojtulewicz
0a47588d0b The remaining nulls 2020-04-07 16:08:34 -07:00
Jon Siwek
6980f63a91 Deprecate EventMgr::QueueEventFast() and update usages to Enqueue() 2020-03-25 16:09:33 -07:00
Jon Siwek
b667c637df Deprecate Func::Call(val_list*, ...)
The version taking a vector of intrusive pointers should be used
instead.  A variadic version is also added that forwards all arguments.
2020-03-24 20:48:32 -07:00
Max Kellermann
50d53b2973 Type: use class IntrusivePtr in VectorType 2020-03-06 09:06:38 +01:00
Max Kellermann
ba35ebec4c Type: return IntrusivePtr 2020-03-06 09:06:38 +01:00
Max Kellermann
0a6ddfb6b5 Val: add TableVal::Assign() overload with IntrusivePtr
Prepare the transition to IntrusivePtr for various callers.
2020-03-06 09:06:38 +01:00
Max Kellermann
a0c831a1bd Func: use class IntrusivePtr 2020-03-06 09:06:37 +01:00
Max Kellermann
edde591748 ID: use class IntrusivePtr 2020-02-27 14:08:00 +01:00
Tim Wojtulewicz
822567b3f9 Merge remote-tracking branch 'origin/topic/jsiwek/32bit-compat'
* origin/topic/jsiwek/32bit-compat:
  Improve formatting of doubles that are close to integers
  Improve HTTP version number comparisons
  Add a 32-bit task to Cirrus CI config
  Replace va_list fmt() overload with vfmt()
  Format tables indexed by patterns consistently across 32-bit/64-bit
  Format interval values consistently across 32-bit/64-bit platforms
2020-02-24 18:49:33 -07:00
Max Kellermann
08128b244f IntrusivePtr: rename detach() to release()
Follow the C++ standard library conventions (here: `std::unique_ptr`).
2020-02-20 08:58:21 +01:00
Jon Siwek
8fed26824b Replace va_list fmt() overload with vfmt()
Using an overload that takes a va_list argument potentially causes
accidental misuse on platforms (e.g. 32-bit) where va_list is
implemented as a type that may collide with commonly-used argument
types.

For example:

    char* c = copy_string("hi");
    fmt("%s", (const char*)c);
    fmt("%s", c);

The first fmt() call correctly goes through fmt(const char*, ...) first,
but the second mistakenly goes through fmt(const char*, va_list) first
because variadic function overloads have lower priority during overload
resolution and va_list on a 32-bit system happens to be defined as a
pointer type that can match with "char*" but not "const char*".
2020-02-14 21:40:36 -08:00
Tim Wojtulewicz
d23b15c08f Use std::move in a few places instead of copying a pass-by-value argument (performance-unnecessary-value-param) 2020-02-11 14:11:22 -08:00
Jon Siwek
43e54c7930 GH-780: Prevent log batches from indefinite buffering
Logs that got sent sparsely or burstily would get buffered for long
periods of time since the logic to flush them only does so on the next
log write.  In the worst case, a subsequent log write could never happen
and cause a log entry to be indefinitely buffered.

This fix introduces a recurring event/timer to simply flush all pending
logs at frequency of Broker::log_batch_interval.
2020-02-05 13:06:52 -08:00
Max Kellermann
0db61f3094 include cleanup
The Zeek code base has very inconsistent #includes.  Many sources
included a few headers, and those headers included other headers, and
in the end, nearly everything is included everywhere, so missing
#includes were never noticed.  Another side effect was a lot of header
bloat which slows down the build.

First step to fix it: in each source file, its own header should be
included first to verify that each header's includes are correct, and
none is missing.

After adding the missing #includes, I replaced lots of #includes
inside headers with class forward declarations.  In most headers,
object pointers are never referenced, so declaring the function
prototypes with forward-declared classes is just fine.

This patch speeds up the build by 19%, because each compilation unit
gets smaller.  Here are the "time" numbers for a fresh build (with a
warm page cache but without ccache):

Before this patch:

 3144.94user 161.63system 3:02.87elapsed 1808%CPU (0avgtext+0avgdata 2168608maxresident)k
 760inputs+12008400outputs (1511major+57747204minor)pagefaults 0swaps

After this patch:

 2565.17user 141.83system 2:25.46elapsed 1860%CPU (0avgtext+0avgdata 1489076maxresident)k
 72576inputs+9130920outputs (1667major+49400430minor)pagefaults 0swaps
2020-02-04 20:51:02 +01:00
Tim Wojtulewicz
fea0339aca Add better error messaging when RegisterFd/UnregisterFd fail 2020-01-31 10:13:10 -07:00
Tim Wojtulewicz
c5462eaa80 Broker manager changes to match the new IOSource API and loop architecture 2020-01-31 10:13:09 -07:00
Dominik Charousset
72e15fe4d4 Integrate review feedback 2019-10-29 21:24:56 +01:00
Dominik Charousset
0f41b063b2 Add and use new IntrusivePt type in Zeek
Manual memory management via Ref/Unref is verbose and prone to error. An
intrusive smart pointer automates the reference counting, makes code
more robust (in particular w.r.t. to exceptions) and reduces boilerplate
code. A big benefit of the intrusive smart pointers for Zeek is that
they can co-exist with the manual memory management. Rather than having
to port the entire code base at once, we can migrate components
one-by-one. In this first step, we add the new template
`IntrusivePtr<T>` and start using it in the Broker Manager. This makes
the previous `unref_guard` obsolete.
2019-10-29 16:49:27 +01:00
Jon Siwek
47235b57a6 Merge remote-tracking branch 'origin/topic/timw/deprecate-int-types'
* origin/topic/timw/deprecate-int-types:
  Deprecate the internal int/uint types in favor of the cstdint types they were based on

Merge adjustments:
  * A bpf type mistakenly got replaced (inside an unlikely #ifdef)
  * Did a few substitutions that got missed (likely due to
    pre-processing out of DEBUG macros)
2019-08-14 15:49:24 -07:00
Jon Siwek
94c380297e Merge remote-tracking branch 'origin/topic/timw/easy-pdict-replacements'
* origin/topic/timw/easy-pdict-replacements:
  Cleanups related to PDict -> std::map replacements
  Remove other simple uses of PDict
  Protocols: Remove uses of PDict
  g_dbgfilemaps: Remove uses of PDict
  Scope: remove uses of PDict
  DFA: remove uses of PDict
  EventRegistry: remove uses of PDict
2019-08-13 20:16:02 -07:00
Jon Siwek
87f85ecca1 Cleanups related to PDict -> std::map replacements 2019-08-13 19:57:42 -07:00
Tim Wojtulewicz
54752ef9a1 Deprecate the internal int/uint types in favor of the cstdint types they were based on 2019-08-12 13:50:07 -07:00
Jon Siwek
b3884de2e5 Fix how Broker/CAF sleep duration options are set
With CAF 0.17.0, these are now reporting an incorrect option name
was being used.
2019-08-02 11:33:00 -07:00
Robin Sommer
13c373086d Merge remote-tracking branch 'origin/topic/zeke/closures' 2019-07-30 02:32:34 +00:00
Zeke Medley
bdc8e0e6c4 Merge branch 'master' of https://github.com/zeek/zeek into topic/robin/closures-merge 2019-07-25 11:23:40 -07:00
Tim Wojtulewicz
6144f459e1 Mark List::append/insert deprecated in favor of push_back/push_front for consistency with Queue 2019-07-22 09:47:43 -07:00
Robin Sommer
1bf0cd29fd Edit pass over changes before merge. 2019-07-20 00:00:51 +00:00
Zeke Medley
1692be4c2d Fix bug in selective cloning. 2019-07-16 15:15:05 -07:00
Tim Wojtulewicz
e51f02737b Convert uses of loop_over_list to ranged-for loops 2019-07-15 19:00:24 -07:00
Zeke Medley
f0798c4b49 Allow serialization of closures over Broker.
anonymous-functions, their closures, can now be sent over broker.
In order to send an anonymous function the receiver must have parsed
a definition of the functon, but it need not to have been evaluated.
See testing/btest/language/closure-sending.zeek for an example of how
this can be done.

This also sends their closures as well as the closures of regular
functions.
2019-07-12 10:31:40 -07:00
Johanna Amann
3cdda7647f Merge remote-tracking branch 'origin/topic/jsiwek/gh-443-fix-timestamp-0-logs'
* origin/topic/jsiwek/gh-443-fix-timestamp-0-logs:
  GH-443: fix uses of timestamp 0 in cluster diagnostic logs
2019-07-01 01:29:41 -07:00
Jon Siwek
5b64c35185 Switch default CAF scheduler policy to work sharing
It may generally be better for our default use-case, as workers may
save a few percent cpu utilization as this policy does not have to
use any polling like the stealing policy does.

This also helps avoid a potential issue with the implementation of
spinlocks used in the work-stealing policy in current CAF versions,
where there's some conditions where lock contention causes a thread
to spin for long periods without relinquishing the cpu to others.
2019-06-28 16:34:33 -07:00
Jon Siwek
430f9a92c6 GH-443: fix uses of timestamp 0 in cluster diagnostic logs
For broker.log and cluster.log: there was a race condition.  A worker's
first IOSource that it processes is potentially Broker if there were
no packets available yet and thread scheduling happens to work out
such that network connections (inside CAF threads) become established
before we enter the main I/O loop.  Such peering establishments would
generate logs with timestamp 0 as there was not yet any code path
taken that would update network_time.

For reporter.log: any non-worker (packet-processing) node would just
unnecessarily use a timestamp of 0 for their reporter messages.
2019-06-27 23:00:42 -07:00
Johanna Amann
a50b06d6c1 Merge remote-tracking branch 'origin/master' into topic/johanna/remove-serializer 2019-06-17 09:50:05 -07:00
Jon Siwek
1ce0fcce49 GH-387: update Broker topic names to use "zeek/" prefix 2019-05-29 15:56:37 -07:00
Jon Siwek
574d2c363a Merge remote-tracking branch 'origin/topic/jsiwek/broker-less-copies'
* origin/topic/jsiwek/broker-less-copies:
  Reduce data copying in Broker message processing
2019-05-28 17:58:59 -07:00
Jon Siwek
ebbeb4517b Merge remote-tracking branch 'origin/topic/jsiwek/broker-store-process-n'
* origin/topic/jsiwek/broker-store-process-n:
  Improve Broker I/O loop integration: less mutex locking
  Improve processing of broker data store responses
2019-05-28 17:43:52 -07:00
Jon Siwek
7f0fb49612 Add an internal getenv wrapper function: zeekenv
It maps newer environment variable names starting with ZEEK to the
legacy names starting with BRO.
2019-05-23 20:42:42 -07:00
Daniel Thayer
1a74516db1 Rename all BRO-prefixed environment variables
For backward compatibility when reading values, we first check
the ZEEK-prefixed value, and if not set, then check the corresponding
BRO-prefixed value.
2019-05-22 00:12:31 -05:00
Johanna Amann
824ccde6fc Merge remote-tracking branch 'origin/master' into topic/johanna/243 2019-05-20 10:14:11 -07:00
Daniel Thayer
3bbd11b1cd Changes needed due to bro-to-zeek renaming in broker 2019-05-15 00:22:05 -05:00
Jon Siwek
3ae4ffc66e Improve Broker I/O loop integration: less mutex locking
Checking a subscriber for available messages required locking a mutex,
but we should never actually need to do that in the main-loop to check
for Broker readiness since we can rely on file descriptor polling.
2019-05-10 09:16:29 -07:00
Johanna Amann
474efe9e69 Remove value serialization.
Note - this compiles, but you cannot run Bro anymore - it crashes
immediately with a 0-pointer access. The reason behind it is that the
required clone functionality does not work anymore.
2019-05-09 11:54:38 -07:00