Commit graph

6667 commits

Author SHA1 Message Date
Tim Wojtulewicz
c8844677f1 Review cleanup
- Add constructors for ConnIDKey, remove BuildConnIDKey()
- Rename protocol stats classes and move to implementation file
- Rename "num" field of protocol stats to "active"
- Explicitly delete copy operations for SessionKey
- Change argument for ProtocolStats methods to const-reference
- Make key validity methods in Session not be virtual
- Rename Session::ClearKey and Session::IsKeyValid
2021-04-29 11:09:35 -07:00
Tim Wojtulewicz
ca553fda27 Rework stats to store handles to the counters 2021-04-29 11:09:35 -07:00
Tim Wojtulewicz
63fd1611ca Rename some connection-specific methods in Session and SessionManager 2021-04-29 10:59:08 -07:00
Tim Wojtulewicz
f92f2e6fd4 Add deprecated version of Sessions.h 2021-04-29 10:24:45 -07:00
Tim Wojtulewicz
db1d753b35 Rename NetSessions to SessionManager
This also includes:
- Deprecating the NetSessions name.
- Renaming the zeek::sessions global to zeek::session_mgr and deprecating the old name.
- Renaming Sessions.{h,cc} to SessionManager.{h,cc}.
2021-04-29 10:24:45 -07:00
Tim Wojtulewicz
f7e3556a67 Store a single map of Sessions instead of split maps of Connections.
This commit also includes:
- Storing the transport protocol in ConnID and ConnIDKey to allow tcp and
  udp connections from the same IP/Port combinations. This happens in the
  core.cisco-fabric-path test, for example.
- Lots of test updates. The reasons for these are two fold. First, with
  the change to only store a single map means that TCP, UDP, and ICMP
  connections are now mixed. When Zeek drains the map at shutdown, it drains
  each of those protocols together instead of separately. The second is
  because of how Sessions are stored in the map. We're now storing them
  keyed by the hash of the key stored by the Session objects, which causes
  them to again be in the map in a different order.
2021-04-29 10:24:45 -07:00
Tim Wojtulewicz
008e2cbaef Convert session stats to use the new telemetry API 2021-04-29 10:24:45 -07:00
Tim Wojtulewicz
8fbab9408a Add new Session base class
This is mostly code copied from the existing Connection class, as that class now
inherits from Session.
2021-04-29 10:24:45 -07:00
Tim Wojtulewicz
c752d76052 Move packet filter out of NetSessions 2021-04-29 10:24:45 -07:00
Tim Wojtulewicz
50713b3c2d Move some code out of NetSessions
- TCPStateStats update when a session is removed was moved to Connection
- Stepping Stone manager moved to a singleton object in SteppingStoneManager
2021-04-29 10:24:44 -07:00
Tim Wojtulewicz
14ffd9646f Merge remote-tracking branch 'origin/topic/bbannier/issue-1517'
* origin/topic/bbannier/issue-1517:
  Add basic testing for Geneve protocol analyzer
  GH-1517: Add Geneve decap support
2021-04-29 09:01:11 -07:00
Jon Siwek
aaabb75f66 Merge remote-tracking branch 'origin/topic/jsiwek/misc-table-stuff'
* origin/topic/jsiwek/misc-table-stuff:
  Add a fatal error condition for invalid Dictionary insertion distances
  Fix using clear_table() within an &expire_func
  Remove saving/restoring of value pointer after calling expire_func
  Avoid allocating a HashKey for no-op table expiry iterations
2021-04-28 13:49:31 -07:00
Jon Siwek
333957df22 Fix -Wsign-compare warnings in Debug{Cmds}.cc 2021-04-28 13:10:38 -07:00
Tim Wojtulewicz
9dee652444 GH-1528: Remove broken Queue/PQueue class, replace with std::deque 2021-04-28 09:26:51 -07:00
Jon Siwek
76fb1e7fd0 Fixes to decode_netbios_name and decode_netbios_name_type BIFs
Fixes to `decode_netbios_name`:

* Improve validation that input string is a NetBIOS encoding
  (32 bytes, with characters ranging from 'A' to 'P').  This helps
  prevent Undefined Behavior of left-shifting negative values.
  Invalid encodings now cause a return-value of an empty string.

* More liberal in what decoded characters are allowed.  Namely,
  spaces are now allowed (but any trailing null-bytes and spaces
  are trimmed, similar to before).

Fixes to `decode_netbios_name_type`:

* Improve validation that input string is a NetBIOS encoding
  (32 bytes, with characters ranging from 'A' to 'P').  This helps
  prevent Undefined Behavior of left-shifting negative values and
  a heap-buffer-overread when the input string is too small.
  Invalid encodings now cause a return-value of 256.
2021-04-27 15:27:04 -07:00
Benjamin Bannier
5b2bf374fd GH-1517: Add Geneve decap support
This patch adds the ability to decap Geneve packets to process the inner
payload. The structure of the analyzer borrows heavily from the VXLAN
analyzer.
2021-04-27 11:21:29 +02:00
Jon Siwek
292e3e18a3 Add a fatal error condition for invalid Dictionary insertion distances
When choosing poor/aggressive values for `table_expire_interval`,
`table_expire_delay`, and/or `table_incremental_step` that tend to
leave tables in state of constant table-expiry-iteration, the underlying
Dictionary is never allowed the chance to complete remapping operations
which re-position entries to more ideal locations (e.g. after
reallocating the table to be able to store more entries).

That situation not only leads to the Dictionary generally having a less
efficient structure, but eventually, the lack of re-positioning may
cause an insertion to calculate the new entry's
distance-from-ideal-position to be a value requiring a full 16-bits or
more (>=65535), but an entry only allows storing 16-bit distance values,
with 65535 being a sentinel value that is supposed to indicate an empty
entry.  Dictionary operations may start misbehaving if that's allowed to
happen.
2021-04-26 23:03:32 -07:00
Jon Siwek
d51bd4bc46 Fix using clear_table() within an &expire_func
This previously crashed since clear_table()/TableVal::RemoveAll() left
behind a stale iterator to the old table causing a heap-use-after-free
when resuming table expiry iteration in TableVal::DoExpire().
2021-04-26 22:49:44 -07:00
Jon Siwek
76483a9efa Remove saving/restoring of value pointer after calling expire_func
It's no longer used for anything.  Previously, it was used to detect
whether the expiry batch finished iterating the entire table or not, but
that's now determined by directly checking if the iterator itself
signifies the end of the table.
2021-04-26 22:31:24 -07:00
Jon Siwek
f28a648057 Avoid allocating a HashKey for no-op table expiry iterations 2021-04-26 22:07:13 -07:00
Jon Siwek
486f187b15 GH-1483: Improve error for mismatched container initialization types
For example, trying to assign a vector, table, set, or record
constructor expression to a global variable of a different type now
provides a more explanatory error message than the previous
"Val::CONVERTER" fatal-error and coredump.
2021-04-20 19:14:13 -07:00
Jon Siwek
e8247c2472 Merge remote-tracking branch 'origin/topic/vern/vector-holes'
* origin/topic/vern/vector-holes:
  Remove NEWS entry regarding changed vector-holes functionality
  Fix potential segfaults in VectorVal Insert/Remove methods
  Fix copy() to work with a vector that has trailing holes
  update test suite for vector holes now being supported for numeric types
  add vector tests for creating holes, "in" operator, "?" operator, copying vectors with holes
  restore support for vectors with holes remove vestigial comment
  fix using ++/-- to vectors that contain holes
2021-04-20 14:43:01 -07:00
Jon Siwek
fd5cdbbe50 Fix potential segfaults in VectorVal Insert/Remove methods
The existence/hole check for managed types was needed to prevent
accessing a nil-optional value.
2021-04-19 19:29:37 -07:00
Jon Siwek
819fc1aac0 Fix copy() to work with a vector that has trailing holes
Previously, the trailing holes would not be preserved in the copy.
2021-04-19 19:23:04 -07:00
Florian Wilkens
2d950ffde9 ssl: rudimentary decryption for TLS 1.2
Several limitations still apply:
- TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 is the only supported cipher suite
- Some tests are broken due to a failing assertion regarding bytestring
- No newly written tests for decryption (the patch was tested extensively for our paper)
- Several small open technical questions marked with FIXME
- Architecture in the ssl module might not be optimal
2021-04-19 17:38:02 +02:00
Jon Siwek
f176da200e Merge remote-tracking branch 'origin/topic/jsiwek/gh-1506-fix-broker-func-indices'
- Extended a btest to cover tables/sets with index types
  (this was originally broken until fixed by GH-1514)

* origin/topic/jsiwek/gh-1506-fix-broker-func-indices:
  GH-1506: Fix Broker unserialization of set/table function indices
2021-04-16 16:03:29 -07:00
Tim Wojtulewicz
df22bdd52e Merge remote-tracking branch 'origin/topic/timw/1487-not-valid-enum'
* origin/topic/timw/1487-not-valid-enum:
  Move an assert() in input/Manager.cc to account for ValueToVal errors
  Add test for config framework
  Fix similar issues with ValueTo* methods in the input framework
  GH-1487: Handle error from ValueToVal instead of ignoring it
2021-04-16 08:08:59 -07:00
Jon Siwek
846cc53780 Merge remote-tracking branch 'origin/topic/jsiwek/fix-table-vector-index'
* origin/topic/jsiwek/fix-table-vector-index:
  Fix indexing of set/table types with a vector
2021-04-15 17:59:31 -07:00
Jon Siwek
7d0d57d33b Merge remote-tracking branch 'origin/topic/jsiwek/gh-1507-sip-junk'
* origin/topic/jsiwek/gh-1507-sip-junk:
  GH-1507: Tolerate junk data before SIP requests
2021-04-15 17:43:51 -07:00
Jon Siwek
df9b57118d Merge remote-tracking branch 'origin/topic/jsiwek/gh-1503-improve-expire-func-type-check'
* origin/topic/jsiwek/gh-1503-improve-expire-func-type-check:
  Extend language.expire-func-type-check btest
  GH-1503: Improve &expire_func compatibility type-checking
2021-04-15 17:42:33 -07:00
Tim Wojtulewicz
97288134c2 Merge remote-tracking branch 'origin/topic/jsiwek/gh-1496-fix-armv7-build'
* origin/topic/jsiwek/gh-1496-fix-armv7-build:
  GH-1496: Fix build on armv7 architecture
2021-04-15 11:55:04 -07:00
Jon Siwek
d3ace9b7ac GH-1506: Fix Broker unserialization of set/table function indices
Zeek function types are serialized as a broker::vector, but the
unserialization logic for Zeek set/table types that use a function for
as an index incorrectly identified it as a composite-index, which also
use broker::vector, rather than a singleton-index, and makes such
unserialization fail.

A general example where this failure can happen in practice is when
trying to unserialize a connection record for which there's a
Conn::RemovalHook, since that's a set[function], and a specific case of
that is use of the Intel Framework in a Zeek cluster.
2021-04-15 01:13:51 -07:00
Jon Siwek
735ac0b4fa Fix indexing of set/table types with a vector
Previous behavor:

  internal error: bad index type in CompositeHash::ComputeSingletonHash
  Aborted (core dumped)
2021-04-14 21:58:14 -07:00
Vern Paxson
c1903afb3b restore support for vectors with holes
remove vestigial comment
2021-04-14 18:16:46 -07:00
Vern Paxson
ff393dbd8a fix using ++/-- to vectors that contain holes 2021-04-14 18:16:19 -07:00
Tim Wojtulewicz
fc3438bda5 Merge remote-tracking branch 'origin/topic/jsiwek/gh-1450-large-double-format'
* origin/topic/jsiwek/gh-1450-large-double-format:
  GH-1450: Improve printing/logging of large double/interval/time values
2021-04-14 16:06:11 -07:00
Tim Wojtulewicz
d579dd4318 Merge remote-tracking branch 'origin/topic/jsiwek/crlf-parsing'
* origin/topic/jsiwek/crlf-parsing:
  Add btest for unterminated pattern parsing error behavior
  GH-1497: Support CRLF line-endings in Zeek scripts and signature files
  Escape non-printables in "unrecognized character" parser error messages
2021-04-14 15:54:42 -07:00
Jon Siwek
183789294f GH-1507: Tolerate junk data before SIP requests
This allows for data that won't match a SIP request method to precede an
actual request and generates a new 'sip_junk_before_request' weird when
encountering such a situation.
2021-04-14 15:34:07 -07:00
Jon Siwek
01f6264c87 GH-1503: Improve &expire_func compatibility type-checking
Previously, incompatible &expire_funcs could mistakenly be used, such as
when using that attribute on the unspecified table()/set()
initializations/assignments, resulting in invalid function calls that
eventually crash Zeek.
2021-04-12 16:27:50 -07:00
Jon Siwek
2793984607 Move an assert() in input/Manager.cc to account for ValueToVal errors 2021-04-12 14:21:41 -07:00
Jon Siwek
952d8de8fd Add btest for unterminated pattern parsing error behavior
And clarified the error message that it's more about finding an
unterminated pattern than knowing for sure there's remaining pattern
text spanning multiple lines.
2021-04-09 11:15:06 -07:00
Jon Siwek
28a150246a GH-1496: Fix build on armv7 architecture 2021-04-09 10:54:53 -07:00
Jon Siwek
312547ab0a GH-1497: Support CRLF line-endings in Zeek scripts and signature files 2021-04-08 20:32:30 -07:00
Jon Siwek
4ae056b1a3 Escape non-printables in "unrecognized character" parser error messages 2021-04-08 20:14:49 -07:00
Jon Siwek
77cf68fda7 Add a check for null packet data in pcap IOSource
Some libpcaps (observed in Myricom's) may claim to have read a packet,
but either did not really read a packet or at least provide no way
to access its contents, so this adds a check for null-data to
handle those cases.
2021-04-08 15:09:41 -07:00
Tim Wojtulewicz
04c201393f Fix similar issues with ValueTo* methods in the input framework 2021-04-08 14:07:16 -07:00
Tim Wojtulewicz
6c52fd502f GH-1493: Fix build with -DENABLE_MOBILE_IPV6 2021-04-07 13:44:18 -07:00
Tim Wojtulewicz
2f69e32233 Merge remote-tracking branch 'origin/topic/jsiwek/intrusiveptr-hash'
* origin/topic/jsiwek/intrusiveptr-hash:
  Change TableVal::ToMap() to return ValPtr-indexed maps
  Add std::hash specialization for IntrusivePtr
  Move IntrusivePtr relational operators to zeek namespace
2021-04-07 11:13:05 -07:00
Jon Siwek
cc15c985ca GH-1450: Improve printing/logging of large double/interval/time values
The modp_dtoa/modp_dtoa2 functions aren't capable of handling double
values larger than INT_MAX and fallback on using sprintf() in that
situation.  Previously, the format string to that sprintf() was "%e",
defaulting to a precision of 6, which is already too few digits to
represent a number known to be larger than INT_MAX.  Now, an sprintf()
is still performed for values larger than INT_MAX and still uses a
scientific notation format, but in a way that uses as many decimal
digits as needed to preserve information.
2021-04-06 19:54:02 -07:00
Jon Siwek
cd8f19328a Merge remote-tracking branch 'origin/topic/neverlord/gh-1408'
- Minor adjustments to header includes, whitespace, and a
  compiler warning fix during merge

* origin/topic/neverlord/gh-1408:
  Add new Timer class to the telemetry API
  Fix build with latest VectorVal API
  Update baselines
  Prefix telemetry BIFs with __
  Expose telemetry API to scripting land
  Add handle types for histogram metrics
  Move duplicated code to detail header
  Adhere to Zeek coding style
  Apply suggestions from code review
  Add telemetry Manager to Zeek setup / teardown
  Add missing whitespaces for Zeek coding style
  Add gauge metric types
  Add scaffold for new metrics API with counters
2021-04-05 14:21:44 -07:00