Commit graph

62 commits

Author SHA1 Message Date
Arne Welzel
c380ee68ca iosource/Manager: Remove superflous includes 2024-11-15 15:55:46 +01:00
Arne Welzel
739a8ac509 iosource/Manager: Reap dry sources while computing timeout
Avoids looping over the sources vector twice and should result
in the same behavior.
2024-07-02 11:32:05 +02:00
Arne Welzel
0451a4038c iosource/Manager: Do not manage lifetime of pkt_src
Now that dry sources are properly reaped and freed, an offline packet
source would be deleted once dry, resulting in GetPktSrc() returning
a wild pointer. Don't manage the packet source lifetime and instead
free it during Manager destruction.
2024-07-02 10:47:08 +02:00
Arne Welzel
fcca8670d3 iosource/Manager: Honor manage_lifetime and dont_count for short-lived IO sources
If an IO source is registered and becomes dry at runtime, the IO
manager would not honor its manage_lifetime or dont_count attribute
during collection, resulting in memory leaks.

This probably hasn't mattered so far as there's no IO sources registered
in-tree at runtime using manage_lifetime=true.
2024-07-02 10:46:59 +02:00
Benjamin Bannier
f5a76c1aed Reformat Zeek in Spicy style
This largely copies over Spicy's `.clang-format` configuration file. The
one place where we deviate is header include order since Zeek depends on
headers being included in a certain order.
2023-10-30 09:40:55 +01:00
Arne Welzel
c390c0203d iosource/Manager: Fix poll_interval updating using not-yet valid IsLive()
Testing io_poll_interval_live tweaks with @dopheide-esnet on a Myricom based
system to reduce CPU usage showed no visible effect.

It turns out, the pkt_src->IsLive() call used to update poll_interval is only
valid *after* calling ->Register() with the source. The conditional updating
of the poll_interval introduced in 4fa3e4b9b4
never worked out how it was intended to.

The fix ensures that

* we actually use a poll_interval of 10 in the live case
* changing io_poll_interval_live does have an effect

This is a bit of a major change due to lowering the default poll_interval
by a magnitude, but that seemed to have been the intention always. It's also
tunable via redef, so worst case it can be adapted via configuration.

As reference, with the default a Pcap::non_fd_timeout of 20usec *and* a
poll_interval of 100, theoretically we'd be trying to ask a non-selectable
packet source 500000 per second for a new packet. This is not a likely packet
rate that a single worker would currently observe or manage to process.
2023-04-06 11:44:50 +02:00
Arne Welzel
46c432dc8b iosource: Make poll intervals configurable
This probably should not be changed by users, but it's useful for
testing and experimentation rather than needing to recompile.

Processing 100 packets without checking an FD based IO source can
actually mean that FD based sources are never checked during a read
of a very small pcap...
2023-03-21 09:15:33 +01:00
Arne Welzel
5f1a85803a iomanager/Poll: Add zero-timeout timeout_src also when there's other events ready
This would generally happen the next loop iteration around anyway, but
seems nice to ensure a zero timeout source will be processed at the same
time as sources with ready FDs.
2023-03-21 09:15:33 +01:00
Arne Welzel
f3fcaf776c iomanager: Collect all sources with zero timeouts as ready
Previously, if two iosources returned 0.0 as their timeout, only
one of them would be considered ready. An always ready source
therefore may starve other ready ones due to this and minimally
this behavior seems surprising.

Offline pcap sources are always ready and return 0.0 for
GetNextTimeout() (unless in pseudo-realtime), so we can
also remove the offline source special case.

One subtle side-effect of this change is that if an IO source
returns a 0.0 timeout *and* it's file descriptor is ready in
the same loop iteration, it may be processed twice.
2023-03-21 09:15:33 +01:00
Tim Wojtulewicz
4cb77c1743 Don't close the kqueue manually on shutdown on Windows 2023-01-19 09:13:33 -07:00
Tim Wojtulewicz
7c4fd382d9 Code modernization: Convert from deprecated C standard library headers 2022-06-27 09:47:31 -07:00
Tim Wojtulewicz
f50777cdab Avoid calling DBG_LOG during signal handling 2022-06-26 20:54:04 +00:00
Tim Wojtulewicz
d06387d4d3 Fixes for iosource::Manager for deadlocks during shutdown 2022-06-26 20:54:04 +00:00
Tim Wojtulewicz
82576f8de2 GH-2136: Clean up DNS_Mgr before shutting down 2022-06-01 09:22:29 -07:00
Tim Wojtulewicz
f9f37b11c6 Add new features to IOSource::Manager, used by DNS_Mgr
- iosource_mgr can now track write events to file descriptors as well
  as read events. This adds an argument to both RegisterFd() and
  UnregisterFd() for setting the mode, defaulting to read.
- IOSources can now implement a ProcessFd() method that allows them to
  handle events to single file descriptors instead of of having to
  loop through/track sets of them at processing time.
2022-04-22 13:10:37 -07:00
Tim Wojtulewicz
e97c14add5 clang-format: Other include ordering changes 2021-09-27 10:49:48 -07:00
Tim Wojtulewicz
30aa4621c5 Minor fixes for build problems after reformatting 2021-09-16 15:36:09 -07:00
Tim Wojtulewicz
b2f171ec69 Reformat the world 2021-09-16 15:35:39 -07:00
Tim Wojtulewicz
96d9115360 GH-1079: Use full paths starting with zeek/ when including files 2020-11-12 12:15:26 -07:00
Jon Siwek
427a7de411 Merge remote-tracking branch 'origin/topic/timw/266-namespaces-part5'
- Did a few whitespace re-adjustments during merge

* origin/topic/timw/266-namespaces-part5:
  Update plugin btests for namespace changes
  Plugins: Clean up explicit uses of namespaces in places where they're not necessary.
  Base: Clean up explicit uses of namespaces in places where they're not necessary.
2020-08-25 19:51:42 -07:00
Tim Wojtulewicz
fe0c22c789 Base: Clean up explicit uses of namespaces in places where they're not necessary.
This commit covers all of the common and base classes.
2020-08-24 12:07:00 -07:00
Jon Siwek
bcef1fc871 Fix a case where PktSrc gets processed twice in one runloop iteration
For a non-live PktSrc, it had a special-case to be considered "ready"
every iteration, but additionally every 1 in 100 iterations (the polling
frequency), if there were no other "ready" IOSources, it would get added
to the "ready" set a 2nd time.

This commit completely excludes PktSrc from being processed during the
1/100 runloop iteration where a Poll() happens.  That exclusion is
desirable for a second reason: if reading a pcap happens to do its final
Process() during that 1/100 polling-iteration and there's other
IOSources ready to process like EventMgr/TimerMgr, those sources have
logic to advance network-time to current-time if a PktSrc is no longer
open.  So in such a case, PktSrc::Process() closes, then
EventMgr::Process() sees there's no longer an active PktSrc and advances
to current-time, then EventMgr::Drain() happens and may dispatch
various events that were previous scheduled, with those events now
unexpectedly seeing a network_time() returning current-time.
2020-08-21 10:26:36 -07:00
Tim Wojtulewicz
0ac3fafe13 Move zeek::net namespace to zeek::run_state namespace.
This also moves all of the code from Net.{h,cc} to RunState.{h,cc} and marks Net.h as deprecated
2020-08-20 16:11:47 -07:00
Tim Wojtulewicz
e7c6d51ae7 Move the functions and variables in Net.h to the zeek::net namespace. This includes moving network_time out of util.h. 2020-08-20 15:55:17 -07:00
Tim Wojtulewicz
be92bd536f Move iosource code to zeek namespaces 2020-08-20 15:55:17 -07:00
Tim Wojtulewicz
886fc102b8 Move DebugLogger to zeek namespaces 2020-07-31 16:23:34 -04:00
Tim Wojtulewicz
bfab224d7c Move Reporter to zeek namespace 2020-07-31 16:22:41 -04:00
Tim Wojtulewicz
834b76f94f Restore globally-namespaced plugin_mgr variable, move zeek::plugin::plugin_mgr to zeek::plugin_mgr 2020-07-31 16:22:04 -04:00
Jon Siwek
4f011a65f4 Remove not-useful code in iosource::Manager::OpenPktSrc
It's generally expected for a PktSrc to not be Open yet right after
instantiation, but rather from InitSource() called during the
registration process.  Besides that, the logic in question would
potentially replace an error message that is useful/detailed with one
that is not.
2020-06-08 18:02:44 -07:00
Jon Siwek
0db5c920f2 Deprecate names in BifConst, replace with zeek::BifConst
Some Val* types are also replaced with IntrusivePtr at the new location
2020-05-14 17:26:00 -07:00
Tim Wojtulewicz
2c8d0f60da Ensure time continues moving forward if a pcap source is suspended 2020-05-01 12:36:57 -07:00
Jon Siwek
1b190906c7 GH-938: fix IO loop iterations sometimes skipping offline pcap sources 2020-04-30 16:19:30 -07:00
Johanna Amann
876c803d75 Merge remote-tracking branch 'origin/topic/timw/776-using-statements'
* origin/topic/timw/776-using-statements:
  Remove 'using namespace std' from SerialTypes.h
  Remove other using statements from headers
  GH-776: Remove using statements added by PR 770

Includes small fixes in files that changed since the merge request was
made.

Also includes a few small indentation fixes.
2020-04-09 13:31:07 -07:00
Tim Wojtulewicz
cb01e098df iosource/threading/input/logging: Replace nulls with nullptr 2020-04-07 16:08:34 -07:00
Tim Wojtulewicz
d53c1454c0 Remove 'using namespace std' from SerialTypes.h
This unfortunately cuases a ton of flow-down changes because a lot of other
code was depending on that definition existing. This has a fairly large chance
to break builds of external plugins, considering how many internal ones it broke.
2020-04-07 15:59:59 -07:00
Tim Wojtulewicz
47d813badc Merge remote-tracking branch 'MaxKellermann/eliminate_code
* MaxKellermann/eliminate_code:
  RE: make the RE_Matcher destructor non-virtual
  analyzer/protocol/smtp: remove unnecessary nullptr check
  analyzer/Manager: remove unnecessary clear() calls from destructor
  analyzer/protocol/http: remove unnecessary empty destructor
  iosource/pcap/Source: remove unused fields `last_hdr`, `last_data`
  iosource/Manager: eliminate two std::string copies
2020-02-14 16:17:31 -07:00
Jon Siwek
b1e96ab952 Fix various format specifiers 2020-02-14 11:10:41 -08:00
Max Kellermann
c6ffec02fc broker: include cleanup 2020-02-13 10:12:03 +01:00
Max Kellermann
4b8b6ec559 iosource/Manager: eliminate two std::string copies 2020-02-13 09:16:00 +01:00
Tim Wojtulewicz
23e82b8121 Restore accidentally reverted change to fix FreeBSD 11 build 2020-02-06 10:25:21 -07:00
Tim Wojtulewicz
4f23c0360a GH-773: Make EventMgr an IOSource so that events interrupt kevent waits 2020-02-05 15:43:37 -05: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
efaa756539 Use ranged-for loops in a few places in iosource Manager 2020-02-03 07:34:27 -07:00
Tim Wojtulewicz
d12d0332a7 Change order of includes in iosource Manager, fixes build on FreeBSD 11 2020-02-01 19:23:17 -07:00
Tim Wojtulewicz
fea0339aca Add better error messaging when RegisterFd/UnregisterFd fail 2020-01-31 10:13:10 -07:00
Tim Wojtulewicz
4fa3e4b9b4 Modify IOSource Manager to implement new loop architecture
- Removes entire FindSoonest method that includes all of the calls to select() for checking for ready sources
- Removes FD_Set checking against IOSources
- Adds system for registering and unregistering file descriptors from IOSources. This allows individual sources to mark themselves as ready to be checked by the loop as they become available.
- Adds entirely new loop architecture based on checking the IOSources for when their next timeout is, and then waiting for either that timeout or when the next source is ready. This also implements the polling based on what the OS supports, instead of just calling select() on all platforms. Currently it supports kqueue, epoll, and plain poll.
- Adds system for pinging the loop to force it to wake up
2020-01-31 10:13:09 -07:00
Tim Wojtulewicz
f16f0360ff Only allow a single trace file (-r) or interface (-i) option on the command-line 2020-01-31 09:34:54 -07:00
Jon Siwek
19b893a5bc Make 0 be a valid packet source timestamp
For fuzzed/damaged/corrupted pcaps, a timestamp of 0 could lead to an
infinite loop in Bro as it interprets that as meaning the packet source
is not ready yet.
2018-06-04 13:56:52 -05:00
Jon Siwek
58ea1ff458 BIT-1408: improve I/O loop and Broker IOSource. 2015-06-03 08:25:49 -05:00
Robin Sommer
0620bc970a Make sure to always delete the remote serializer.
There were two problems actually: the iomanager wasn't properly
deleting sourcesl; and in some situations, the remote serialize wasn't
registered with it to begin with.

Addresses BIT-1306 and probably also BIT-1356.
2015-04-10 21:51:44 -07:00