From 9cb54f5d449b63006cc9a1f451a47732c92fef2d Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Fri, 24 Sep 2021 14:36:18 -0700 Subject: [PATCH 1/7] clang-format: Force zeek-config.h to be earlier in the config ordering --- .clang-format | 7 +++++-- src/Attr.cc | 3 ++- src/Base64.cc | 3 ++- src/Base64.h | 4 ++-- src/BifReturnVal.h | 3 ++- src/CCL.cc | 3 ++- src/CompHash.cc | 3 ++- src/Conn.cc | 3 ++- src/DFA.cc | 3 ++- src/DNS_Mgr.cc | 4 ++-- src/DbgBreakpoint.cc | 3 ++- src/DbgHelp.cc | 3 ++- src/DbgWatch.cc | 3 ++- src/Debug.cc | 4 ++-- src/DebugCmds.cc | 3 ++- src/DebugLogger.h | 4 ++-- src/Desc.cc | 3 ++- src/Discard.cc | 3 ++- src/EquivClass.cc | 3 ++- src/Event.cc | 3 ++- src/EventRegistry.h | 4 ++-- src/Expr.cc | 3 ++- src/File.cc | 4 ++-- src/Frag.cc | 3 ++- src/Func.cc | 4 ++-- src/Hash.cc | 3 ++- src/ID.cc | 3 ++- src/IP.h | 6 +++--- src/NFA.cc | 3 ++- src/NetVar.cc | 3 ++- src/Obj.cc | 3 ++- src/Obj.h | 4 ++-- src/Options.cc | 3 ++- src/PolicyFile.cc | 3 ++- src/PriorityQueue.cc | 3 ++- src/PriorityQueue.h | 4 ++-- src/RE.cc | 3 ++- src/RandTest.h | 4 ++-- src/Reassem.cc | 3 ++- src/Reporter.cc | 3 ++- src/Rule.cc | 3 ++- src/RuleAction.cc | 3 ++- src/RuleCondition.cc | 3 ++- src/RuleMatcher.cc | 3 ++- src/RunState.cc | 4 ++-- src/RunState.h | 4 ++-- src/Scope.cc | 3 ++- src/SerializationFormat.h | 4 ++-- src/SmithWaterman.cc | 3 ++- src/Stats.h | 4 ++-- src/Stmt.cc | 3 ++- src/Tag.h | 3 ++- src/Timer.cc | 3 ++- src/TunnelEncapsulation.h | 3 ++- src/Type.cc | 3 ++- src/Val.cc | 3 ++- src/Var.cc | 3 ++- src/ZeekString.cc | 3 ++- src/ZeekString.h | 4 ++-- src/analyzer/Component.h | 3 ++- src/analyzer/Tag.h | 3 ++- src/analyzer/protocol/dce-rpc/DCE_RPC.cc | 4 ++-- src/analyzer/protocol/dns/DNS.cc | 3 ++- src/analyzer/protocol/finger/Finger.cc | 3 ++- src/analyzer/protocol/ftp/FTP.cc | 3 ++- src/analyzer/protocol/gnutella/Gnutella.cc | 3 ++- src/analyzer/protocol/http/HTTP.cc | 3 ++- src/analyzer/protocol/ident/Ident.cc | 3 ++- src/analyzer/protocol/krb/KRB.h | 4 ++-- src/analyzer/protocol/login/Login.cc | 3 ++- src/analyzer/protocol/login/NVT.cc | 3 ++- src/analyzer/protocol/login/RSH.cc | 3 ++- src/analyzer/protocol/login/Rlogin.cc | 3 ++- src/analyzer/protocol/login/Telnet.cc | 3 ++- src/analyzer/protocol/mime/MIME.cc | 3 ++- src/analyzer/protocol/ncp/NCP.cc | 3 ++- src/analyzer/protocol/netbios/NetbiosSSN.cc | 3 ++- src/analyzer/protocol/pop3/POP3.cc | 3 ++- src/analyzer/protocol/rpc/MOUNT.cc | 3 ++- src/analyzer/protocol/rpc/NFS.cc | 3 ++- src/analyzer/protocol/rpc/Portmap.cc | 3 ++- src/analyzer/protocol/rpc/RPC.cc | 3 ++- src/analyzer/protocol/rpc/XDR.cc | 3 ++- src/analyzer/protocol/smtp/SMTP.cc | 3 ++- src/analyzer/protocol/zip/ZIP.h | 3 ++- src/broker/Manager.cc | 2 +- src/file_analysis/Component.h | 3 ++- src/file_analysis/Tag.h | 3 ++- src/input/Tag.h | 3 ++- src/input/readers/sqlite/SQLite.cc | 3 ++- src/input/readers/sqlite/SQLite.h | 3 ++- src/iosource/BPF_Program.cc | 4 ++-- src/iosource/Manager.h | 3 ++- src/iosource/Packet.h | 4 ++-- src/iosource/PktDumper.cc | 3 ++- src/iosource/PktDumper.h | 4 ++-- src/iosource/PktSrc.cc | 3 ++- src/logging/Tag.h | 3 ++- src/logging/writers/sqlite/SQLite.cc | 3 ++- src/logging/writers/sqlite/SQLite.h | 3 ++- src/main.cc | 3 ++- src/net_util.cc | 3 ++- src/packet_analysis/Component.h | 3 ++- src/packet_analysis/Tag.h | 3 ++- src/plugin/Component.h | 4 ++-- src/plugin/Plugin.h | 3 ++- src/probabilistic/BloomFilter.h | 3 ++- src/probabilistic/CounterVector.h | 4 ++-- src/session/Manager.cc | 3 ++- src/supervisor/Supervisor.cc | 4 ++-- src/threading/BasicThread.cc | 3 ++- src/threading/BasicThread.h | 4 ++-- src/threading/Formatter.cc | 3 ++- src/threading/formatters/Ascii.cc | 3 ++- src/zeek-setup.cc | 3 ++- src/zeekygen/ScriptInfo.h | 3 ++- src/zeekygen/Target.h | 4 ++-- src/zeekygen/utils.h | 4 ++-- 118 files changed, 239 insertions(+), 147 deletions(-) diff --git a/.clang-format b/.clang-format index 4b5f426689..14203ffdc7 100644 --- a/.clang-format +++ b/.clang-format @@ -81,11 +81,14 @@ IncludeBlocks: Regroup # 5: everything else, which should catch any of the auto-generated code from the # build directory as well # -# Sections 0-1 and 2-3 get group together in their respective blocks +# Sections 0-1 and 2-3 get grouped together in their respective blocks IncludeCategories: - Regex: '^"zeek-config\.h"' - Priority: 0 + Priority: 1 SortPriority: 1 + - Regex: '^"zeek/zeek-config\.h"' + Priority: 1 + SortPriority: 2 - Regex: '^<[[:print:]]+\.(h|hh)>' Priority: 2 SortPriority: 2 diff --git a/src/Attr.cc b/src/Attr.cc index d3375c6826..d5a25cfc1e 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -2,13 +2,14 @@ #include "zeek/Attr.h" +#include "zeek/zeek-config.h" + #include "zeek/Desc.h" #include "zeek/Expr.h" #include "zeek/IntrusivePtr.h" #include "zeek/Val.h" #include "zeek/input/Manager.h" #include "zeek/threading/SerialTypes.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/Base64.cc b/src/Base64.cc index 1fe2a633c1..7e76f42520 100644 --- a/src/Base64.cc +++ b/src/Base64.cc @@ -1,11 +1,12 @@ #include "zeek/Base64.h" +#include "zeek/zeek-config.h" + #include #include "zeek/Conn.h" #include "zeek/Reporter.h" #include "zeek/ZeekString.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/Base64.h b/src/Base64.h index 8c262646cd..943cb52391 100644 --- a/src/Base64.h +++ b/src/Base64.h @@ -1,9 +1,9 @@ #pragma once -#include - #include "zeek/zeek-config.h" +#include + namespace zeek { diff --git a/src/BifReturnVal.h b/src/BifReturnVal.h index 817df6aa50..70fd901ba2 100644 --- a/src/BifReturnVal.h +++ b/src/BifReturnVal.h @@ -2,9 +2,10 @@ #pragma once -#include "zeek/IntrusivePtr.h" #include "zeek/zeek-config.h" +#include "zeek/IntrusivePtr.h" + namespace zeek { diff --git a/src/CCL.cc b/src/CCL.cc index 68503e241c..02d23d9bac 100644 --- a/src/CCL.cc +++ b/src/CCL.cc @@ -2,11 +2,12 @@ #include "zeek/CCL.h" +#include "zeek/zeek-config.h" + #include #include "zeek/DFA.h" #include "zeek/RE.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/CompHash.cc b/src/CompHash.cc index 50e8f446f6..72fe39364f 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -2,6 +2,8 @@ #include "zeek/CompHash.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -13,7 +15,6 @@ #include "zeek/Reporter.h" #include "zeek/Val.h" #include "zeek/ZeekString.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/Conn.cc b/src/Conn.cc index e11e149a8e..46d057a268 100644 --- a/src/Conn.cc +++ b/src/Conn.cc @@ -2,6 +2,8 @@ #include "zeek/Conn.h" +#include "zeek/zeek-config.h" + #include #include @@ -19,7 +21,6 @@ #include "zeek/packet_analysis/protocol/ip/SessionAdapter.h" #include "zeek/packet_analysis/protocol/tcp/TCP.h" #include "zeek/session/Manager.h" -#include "zeek/zeek-config.h" namespace zeek { diff --git a/src/DFA.cc b/src/DFA.cc index 99c3a04499..6a2c018813 100644 --- a/src/DFA.cc +++ b/src/DFA.cc @@ -2,10 +2,11 @@ #include "zeek/DFA.h" +#include "zeek/zeek-config.h" + #include "zeek/Desc.h" #include "zeek/EquivClass.h" #include "zeek/Hash.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index 79365930b9..408fda9f10 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -2,10 +2,10 @@ #include "zeek/DNS_Mgr.h" +#include "zeek/zeek-config.h" + #include #include - -#include "zeek/zeek-config.h" #ifdef TIME_WITH_SYS_TIME #include #include diff --git a/src/DbgBreakpoint.cc b/src/DbgBreakpoint.cc index d15fa005cf..b309326b23 100644 --- a/src/DbgBreakpoint.cc +++ b/src/DbgBreakpoint.cc @@ -2,6 +2,8 @@ #include "zeek/DbgBreakpoint.h" +#include "zeek/zeek-config.h" + #include #include "zeek/Debug.h" @@ -15,7 +17,6 @@ #include "zeek/Timer.h" #include "zeek/Val.h" #include "zeek/module_util.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/DbgHelp.cc b/src/DbgHelp.cc index 9d51d4201b..373f0c0613 100644 --- a/src/DbgHelp.cc +++ b/src/DbgHelp.cc @@ -1,4 +1,5 @@ // Bro Debugger Help -#include "zeek/Debug.h" #include "zeek/zeek-config.h" + +#include "zeek/Debug.h" diff --git a/src/DbgWatch.cc b/src/DbgWatch.cc index 985ba098d5..a5a9fc3f0d 100644 --- a/src/DbgWatch.cc +++ b/src/DbgWatch.cc @@ -2,9 +2,10 @@ #include "zeek/DbgWatch.h" +#include "zeek/zeek-config.h" + #include "zeek/Debug.h" #include "zeek/Reporter.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/Debug.cc b/src/Debug.cc index 60fac5eeb7..d29daf842b 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -2,14 +2,14 @@ #include "zeek/Debug.h" +#include "zeek/zeek-config.h" + #include #include #include #include #include -#include "zeek/zeek-config.h" - #ifdef HAVE_READLINE #include #include diff --git a/src/DebugCmds.cc b/src/DebugCmds.cc index 866a5efbff..3f69bccbd7 100644 --- a/src/DebugCmds.cc +++ b/src/DebugCmds.cc @@ -3,6 +3,8 @@ #include "zeek/DebugCmds.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -21,7 +23,6 @@ #include "zeek/Stmt.h" #include "zeek/Val.h" #include "zeek/util.h" -#include "zeek/zeek-config.h" using namespace std; diff --git a/src/DebugLogger.h b/src/DebugLogger.h index ed8f9a7d37..ce2aae57dc 100644 --- a/src/DebugLogger.h +++ b/src/DebugLogger.h @@ -5,12 +5,12 @@ #ifdef DEBUG +#include "zeek/zeek-config.h" + #include #include #include -#include "zeek/zeek-config.h" - #define DBG_LOG(stream, args...) \ if ( ::zeek::detail::debug_logger.IsEnabled(stream) ) \ ::zeek::detail::debug_logger.Log(stream, args) diff --git a/src/Desc.cc b/src/Desc.cc index a02397cfe5..25b70a1e77 100644 --- a/src/Desc.cc +++ b/src/Desc.cc @@ -2,6 +2,8 @@ #include "zeek/Desc.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -11,7 +13,6 @@ #include "zeek/File.h" #include "zeek/IPAddr.h" #include "zeek/Reporter.h" -#include "zeek/zeek-config.h" #define DEFAULT_SIZE 128 #define SLOP 10 diff --git a/src/Discard.cc b/src/Discard.cc index 5a6dbcbe2f..ba36754451 100644 --- a/src/Discard.cc +++ b/src/Discard.cc @@ -2,6 +2,8 @@ #include "zeek/Discard.h" +#include "zeek/zeek-config.h" + #include #include "zeek/Func.h" @@ -11,7 +13,6 @@ #include "zeek/Val.h" #include "zeek/Var.h" #include "zeek/ZeekString.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/EquivClass.cc b/src/EquivClass.cc index 81c3e56c39..7fba212541 100644 --- a/src/EquivClass.cc +++ b/src/EquivClass.cc @@ -2,9 +2,10 @@ #include "zeek/EquivClass.h" +#include "zeek/zeek-config.h" + #include "zeek/CCL.h" #include "zeek/util.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/Event.cc b/src/Event.cc index 86ba5269d1..c6dfc5365a 100644 --- a/src/Event.cc +++ b/src/Event.cc @@ -2,6 +2,8 @@ #include "zeek/Event.h" +#include "zeek/zeek-config.h" + #include "zeek/Desc.h" #include "zeek/Func.h" #include "zeek/NetVar.h" @@ -11,7 +13,6 @@ #include "zeek/iosource/Manager.h" #include "zeek/iosource/PktSrc.h" #include "zeek/plugin/Manager.h" -#include "zeek/zeek-config.h" zeek::EventMgr zeek::event_mgr; zeek::EventMgr& mgr = zeek::event_mgr; diff --git a/src/EventRegistry.h b/src/EventRegistry.h index 6d5c6a5853..5b48334bbc 100644 --- a/src/EventRegistry.h +++ b/src/EventRegistry.h @@ -2,14 +2,14 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include #include #include #include -#include "zeek/zeek-config.h" - namespace zeek { diff --git a/src/Expr.cc b/src/Expr.cc index 840223fc1d..42b6350613 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2,6 +2,8 @@ #include "zeek/Expr.h" +#include "zeek/zeek-config.h" + #include "zeek/DebugLogger.h" #include "zeek/Desc.h" #include "zeek/Event.h" @@ -20,7 +22,6 @@ #include "zeek/digest.h" #include "zeek/module_util.h" #include "zeek/script_opt/ExprOptInfo.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/File.cc b/src/File.cc index 67c07399dc..00fa141b3a 100644 --- a/src/File.cc +++ b/src/File.cc @@ -2,9 +2,9 @@ #include "zeek/File.h" -#include - #include "zeek/zeek-config.h" + +#include #ifdef TIME_WITH_SYS_TIME #include #include diff --git a/src/Frag.cc b/src/Frag.cc index 7b3b4d9237..06a940008e 100644 --- a/src/Frag.cc +++ b/src/Frag.cc @@ -2,13 +2,14 @@ #include "zeek/Frag.h" +#include "zeek/zeek-config.h" + #include "zeek/Hash.h" #include "zeek/IP.h" #include "zeek/NetVar.h" #include "zeek/Reporter.h" #include "zeek/RunState.h" #include "zeek/session/Manager.h" -#include "zeek/zeek-config.h" constexpr uint32_t MIN_ACCEPTABLE_FRAG_SIZE = 64; constexpr uint32_t MAX_ACCEPTABLE_FRAG_SIZE = 64000; diff --git a/src/Func.cc b/src/Func.cc index 46ada094af..355544362e 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -3,10 +3,10 @@ #include "zeek/Func.h" +#include "zeek/zeek-config.h" + #include #include - -#include "zeek/zeek-config.h" #ifdef TIME_WITH_SYS_TIME #include #include diff --git a/src/Hash.cc b/src/Hash.cc index 740a26b167..a81ad750f9 100644 --- a/src/Hash.cc +++ b/src/Hash.cc @@ -2,6 +2,8 @@ #include "zeek/Hash.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -12,7 +14,6 @@ #include "zeek/Val.h" // needed for const.bif #include "zeek/ZeekString.h" #include "zeek/digest.h" -#include "zeek/zeek-config.h" #include "const.bif.netvar_h" diff --git a/src/ID.cc b/src/ID.cc index b5ad900e07..b58cf2e872 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -3,6 +3,8 @@ #include "zeek/ID.h" +#include "zeek/zeek-config.h" + #include "zeek/Attr.h" #include "zeek/Desc.h" #include "zeek/Dict.h" @@ -16,7 +18,6 @@ #include "zeek/Val.h" #include "zeek/module_util.h" #include "zeek/script_opt/IDOptInfo.h" -#include "zeek/zeek-config.h" #include "zeek/zeekygen/IdentifierInfo.h" #include "zeek/zeekygen/Manager.h" #include "zeek/zeekygen/ScriptInfo.h" diff --git a/src/IP.h b/src/IP.h index 7e8e99f762..8aebb72d92 100644 --- a/src/IP.h +++ b/src/IP.h @@ -2,11 +2,11 @@ #pragma once -#include // for u_char +#include "zeek/zeek-config.h" + #include #include - -#include "zeek/zeek-config.h" +#include // for u_char #ifdef HAVE_NETINET_IP6_H #include diff --git a/src/NFA.cc b/src/NFA.cc index 88f1199e9f..0d3a6d9c79 100644 --- a/src/NFA.cc +++ b/src/NFA.cc @@ -2,12 +2,13 @@ #include "zeek/NFA.h" +#include "zeek/zeek-config.h" + #include #include "zeek/Desc.h" #include "zeek/EquivClass.h" #include "zeek/IntSet.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/NetVar.cc b/src/NetVar.cc index c12623ffbd..6f3acb2ad1 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -2,11 +2,12 @@ #include "zeek/NetVar.h" +#include "zeek/zeek-config.h" + #include "zeek/EventHandler.h" #include "zeek/ID.h" #include "zeek/Val.h" #include "zeek/Var.h" -#include "zeek/zeek-config.h" zeek::RecordType* conn_id; zeek::RecordType* endpoint; diff --git a/src/Obj.cc b/src/Obj.cc index 413f0472ad..3a36e39e49 100644 --- a/src/Obj.cc +++ b/src/Obj.cc @@ -2,13 +2,14 @@ #include "zeek/Obj.h" +#include "zeek/zeek-config.h" + #include #include "zeek/Desc.h" #include "zeek/File.h" #include "zeek/Func.h" #include "zeek/plugin/Manager.h" -#include "zeek/zeek-config.h" namespace zeek { diff --git a/src/Obj.h b/src/Obj.h index 041db27df3..26a79fbb70 100644 --- a/src/Obj.h +++ b/src/Obj.h @@ -2,10 +2,10 @@ #pragma once -#include - #include "zeek/zeek-config.h" +#include + namespace zeek { diff --git a/src/Options.cc b/src/Options.cc index cfd315a237..9bc235cbcc 100644 --- a/src/Options.cc +++ b/src/Options.cc @@ -2,10 +2,11 @@ #include "zeek/Options.h" +#include "zeek/zeek-config.h" + #include #include "zeek/script_opt/ScriptOpt.h" -#include "zeek/zeek-config.h" #ifdef HAVE_GETOPT_H #include diff --git a/src/PolicyFile.cc b/src/PolicyFile.cc index f7f268d9b6..5176cf1539 100644 --- a/src/PolicyFile.cc +++ b/src/PolicyFile.cc @@ -1,5 +1,7 @@ #include "zeek/PolicyFile.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -12,7 +14,6 @@ #include "zeek/Debug.h" #include "zeek/Reporter.h" #include "zeek/util.h" -#include "zeek/zeek-config.h" using namespace std; diff --git a/src/PriorityQueue.cc b/src/PriorityQueue.cc index e95f6dd711..4a0397b004 100644 --- a/src/PriorityQueue.cc +++ b/src/PriorityQueue.cc @@ -2,12 +2,13 @@ #include "zeek/PriorityQueue.h" +#include "zeek/zeek-config.h" + #include #include #include "zeek/Reporter.h" #include "zeek/util.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/PriorityQueue.h b/src/PriorityQueue.h index 08c5ce8cf1..d0e27219fa 100644 --- a/src/PriorityQueue.h +++ b/src/PriorityQueue.h @@ -2,11 +2,11 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include -#include "zeek/zeek-config.h" - namespace zeek::detail { diff --git a/src/RE.cc b/src/RE.cc index 8f59592949..7e6443d40c 100644 --- a/src/RE.cc +++ b/src/RE.cc @@ -2,6 +2,8 @@ #include "zeek/RE.h" +#include "zeek/zeek-config.h" + #include #include @@ -10,7 +12,6 @@ #include "zeek/EquivClass.h" #include "zeek/Reporter.h" #include "zeek/ZeekString.h" -#include "zeek/zeek-config.h" zeek::detail::CCL* zeek::detail::curr_ccl = nullptr; zeek::detail::Specific_RE_Matcher* zeek::detail::rem = nullptr; diff --git a/src/RandTest.h b/src/RandTest.h index e3be5e997e..fa44827c89 100644 --- a/src/RandTest.h +++ b/src/RandTest.h @@ -1,9 +1,9 @@ #pragma once -#include - #include "zeek/zeek-config.h" +#include + #define RT_MONTEN \ 6 /* Bytes used as Monte Carlo \ co-ordinates. This should be no more \ diff --git a/src/Reassem.cc b/src/Reassem.cc index e7eba0e82d..5ab359211e 100644 --- a/src/Reassem.cc +++ b/src/Reassem.cc @@ -2,10 +2,11 @@ #include "zeek/Reassem.h" +#include "zeek/zeek-config.h" + #include #include "zeek/Desc.h" -#include "zeek/zeek-config.h" using std::min; diff --git a/src/Reporter.cc b/src/Reporter.cc index e9b3fb67f4..33ff1be1ba 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -4,6 +4,8 @@ #include "zeek/Reporter.h" +#include "zeek/zeek-config.h" + #include #include @@ -20,7 +22,6 @@ #include "zeek/input.h" #include "zeek/plugin/Manager.h" #include "zeek/plugin/Plugin.h" -#include "zeek/zeek-config.h" #ifdef SYSLOG_INT extern "C" diff --git a/src/Rule.cc b/src/Rule.cc index 6653fc5b7a..82a8301883 100644 --- a/src/Rule.cc +++ b/src/Rule.cc @@ -1,9 +1,10 @@ #include "zeek/Rule.h" +#include "zeek/zeek-config.h" + #include "zeek/RuleAction.h" #include "zeek/RuleCondition.h" #include "zeek/RuleMatcher.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/RuleAction.cc b/src/RuleAction.cc index 319d59703d..32feb824e8 100644 --- a/src/RuleAction.cc +++ b/src/RuleAction.cc @@ -1,5 +1,7 @@ #include "zeek/RuleAction.h" +#include "zeek/zeek-config.h" + #include #include "zeek/Conn.h" @@ -8,7 +10,6 @@ #include "zeek/RuleMatcher.h" #include "zeek/analyzer/Manager.h" #include "zeek/analyzer/protocol/pia/PIA.h" -#include "zeek/zeek-config.h" using std::string; diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index 5058c6bfda..39d21e9a4b 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -1,5 +1,7 @@ #include "zeek/RuleCondition.h" +#include "zeek/zeek-config.h" + #include "zeek/Func.h" #include "zeek/ID.h" #include "zeek/Reporter.h" @@ -7,7 +9,6 @@ #include "zeek/Scope.h" #include "zeek/Val.h" #include "zeek/analyzer/protocol/tcp/TCP.h" -#include "zeek/zeek-config.h" static inline bool is_established(const zeek::analyzer::tcp::TCP_Endpoint* e) { diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index 2745b487b9..d8d709cdf0 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -1,6 +1,8 @@ #include "zeek/RuleMatcher.h" +#include "zeek/zeek-config.h" + #include #include @@ -22,7 +24,6 @@ #include "zeek/ZeekString.h" #include "zeek/analyzer/Analyzer.h" #include "zeek/module_util.h" -#include "zeek/zeek-config.h" using namespace std; diff --git a/src/RunState.cc b/src/RunState.cc index b5cfc49a0a..96bb7a5b2a 100644 --- a/src/RunState.cc +++ b/src/RunState.cc @@ -2,9 +2,9 @@ #include "zeek/RunState.h" -#include - #include "zeek/zeek-config.h" + +#include #ifdef TIME_WITH_SYS_TIME #include #include diff --git a/src/RunState.h b/src/RunState.h index 53ce03f988..6bba345b74 100644 --- a/src/RunState.h +++ b/src/RunState.h @@ -2,11 +2,11 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include -#include "zeek/zeek-config.h" - namespace zeek { diff --git a/src/Scope.cc b/src/Scope.cc index 99dde7fc84..ce8438bb44 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -2,13 +2,14 @@ #include "zeek/Scope.h" +#include "zeek/zeek-config.h" + #include "zeek/Desc.h" #include "zeek/ID.h" #include "zeek/IntrusivePtr.h" #include "zeek/Reporter.h" #include "zeek/Val.h" #include "zeek/module_util.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/SerializationFormat.h b/src/SerializationFormat.h index f24f2bcf5b..e0eb139285 100644 --- a/src/SerializationFormat.h +++ b/src/SerializationFormat.h @@ -2,11 +2,11 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include -#include "zeek/zeek-config.h" - struct in_addr; struct in6_addr; diff --git a/src/SmithWaterman.cc b/src/SmithWaterman.cc index 1f4ad09fa6..c02fe2bc37 100644 --- a/src/SmithWaterman.cc +++ b/src/SmithWaterman.cc @@ -2,6 +2,8 @@ #include "zeek/SmithWaterman.h" +#include "zeek/zeek-config.h" + #include #include @@ -9,7 +11,6 @@ #include "zeek/Val.h" #include "zeek/Var.h" #include "zeek/util.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/Stats.h b/src/Stats.h index deae924ae8..ab3a2f6fa8 100644 --- a/src/Stats.h +++ b/src/Stats.h @@ -2,13 +2,13 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include #include #include -#include "zeek/zeek-config.h" - namespace zeek { diff --git a/src/Stmt.cc b/src/Stmt.cc index 5ead79efe5..e2a01395b8 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -2,6 +2,8 @@ #include "zeek/Stmt.h" +#include "zeek/zeek-config.h" + #include "zeek/CompHash.h" #include "zeek/Debug.h" #include "zeek/Desc.h" @@ -19,7 +21,6 @@ #include "zeek/logging/Manager.h" #include "zeek/logging/logging.bif.h" #include "zeek/script_opt/StmtOptInfo.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/Tag.h b/src/Tag.h index da88e999a1..086adee438 100644 --- a/src/Tag.h +++ b/src/Tag.h @@ -2,12 +2,13 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include #include "zeek/IntrusivePtr.h" #include "zeek/util.h" -#include "zeek/zeek-config.h" namespace zeek { diff --git a/src/Timer.cc b/src/Timer.cc index 3582bfecea..0bc71e072c 100644 --- a/src/Timer.cc +++ b/src/Timer.cc @@ -2,6 +2,8 @@ #include "zeek/Timer.h" +#include "zeek/zeek-config.h" + #include "zeek/Desc.h" #include "zeek/NetVar.h" #include "zeek/RunState.h" @@ -9,7 +11,6 @@ #include "zeek/iosource/Manager.h" #include "zeek/iosource/PktSrc.h" #include "zeek/util.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/TunnelEncapsulation.h b/src/TunnelEncapsulation.h index 4775b9421d..960886a1a3 100644 --- a/src/TunnelEncapsulation.h +++ b/src/TunnelEncapsulation.h @@ -2,13 +2,14 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include "zeek/ID.h" #include "zeek/IPAddr.h" #include "zeek/NetVar.h" #include "zeek/UID.h" -#include "zeek/zeek-config.h" namespace zeek { diff --git a/src/Type.cc b/src/Type.cc index 1de76d9880..0d3a6e10cc 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -2,6 +2,8 @@ #include "zeek/Type.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -14,7 +16,6 @@ #include "zeek/Val.h" #include "zeek/Var.h" #include "zeek/module_util.h" -#include "zeek/zeek-config.h" #include "zeek/zeekygen/IdentifierInfo.h" #include "zeek/zeekygen/Manager.h" #include "zeek/zeekygen/ScriptInfo.h" diff --git a/src/Val.cc b/src/Val.cc index 9e9ad5fdbc..294ffebd5a 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2,6 +2,8 @@ #include "zeek/Val.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -35,7 +37,6 @@ #include "zeek/broker/Manager.h" #include "zeek/broker/Store.h" #include "zeek/threading/formatters/JSON.h" -#include "zeek/zeek-config.h" using namespace std; diff --git a/src/Var.cc b/src/Var.cc index 85f53cc3d6..e0d7f7c4c5 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -2,6 +2,8 @@ #include "zeek/Var.h" +#include "zeek/zeek-config.h" + #include #include "zeek/EventRegistry.h" @@ -16,7 +18,6 @@ #include "zeek/Val.h" #include "zeek/module_util.h" #include "zeek/script_opt/ScriptOpt.h" -#include "zeek/zeek-config.h" namespace zeek::detail { diff --git a/src/ZeekString.cc b/src/ZeekString.cc index a939cde264..b62c661b1b 100644 --- a/src/ZeekString.cc +++ b/src/ZeekString.cc @@ -2,6 +2,8 @@ #include "zeek/ZeekString.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -12,7 +14,6 @@ #include "zeek/Reporter.h" #include "zeek/Val.h" #include "zeek/util.h" -#include "zeek/zeek-config.h" #ifdef DEBUG #define DEBUG_STR(msg) DBG_LOG(zeek::DBG_STRING, msg) diff --git a/src/ZeekString.h b/src/ZeekString.h index c8a4f655a2..8db2c26542 100644 --- a/src/ZeekString.h +++ b/src/ZeekString.h @@ -2,13 +2,13 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include #include #include -#include "zeek/zeek-config.h" - namespace zeek { diff --git a/src/analyzer/Component.h b/src/analyzer/Component.h index 0d130e3eee..ebb2fb01c0 100644 --- a/src/analyzer/Component.h +++ b/src/analyzer/Component.h @@ -2,11 +2,12 @@ #pragma once +#include "zeek/zeek-config.h" + #include "zeek/analyzer/Tag.h" #include "zeek/plugin/Component.h" #include "zeek/plugin/TaggedComponent.h" #include "zeek/util.h" -#include "zeek/zeek-config.h" namespace zeek { diff --git a/src/analyzer/Tag.h b/src/analyzer/Tag.h index 7b4f032f89..f5f291d66e 100644 --- a/src/analyzer/Tag.h +++ b/src/analyzer/Tag.h @@ -3,9 +3,10 @@ #pragma once -#include "zeek/Tag.h" #include "zeek/zeek-config.h" +#include "zeek/Tag.h" + namespace zeek { diff --git a/src/analyzer/protocol/dce-rpc/DCE_RPC.cc b/src/analyzer/protocol/dce-rpc/DCE_RPC.cc index 986ed61c06..b998c5a34e 100644 --- a/src/analyzer/protocol/dce-rpc/DCE_RPC.cc +++ b/src/analyzer/protocol/dce-rpc/DCE_RPC.cc @@ -2,12 +2,12 @@ #include "zeek/analyzer/protocol/dce-rpc/DCE_RPC.h" +#include "zeek/zeek-config.h" + #include #include #include -#include "zeek/zeek-config.h" - using namespace std; namespace zeek::analyzer::dce_rpc diff --git a/src/analyzer/protocol/dns/DNS.cc b/src/analyzer/protocol/dns/DNS.cc index e297fd767a..952e470b07 100644 --- a/src/analyzer/protocol/dns/DNS.cc +++ b/src/analyzer/protocol/dns/DNS.cc @@ -2,6 +2,8 @@ #include "zeek/analyzer/protocol/dns/DNS.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -14,7 +16,6 @@ #include "zeek/ZeekString.h" #include "zeek/analyzer/protocol/dns/events.bif.h" #include "zeek/session/Manager.h" -#include "zeek/zeek-config.h" namespace zeek::analyzer::dns { diff --git a/src/analyzer/protocol/finger/Finger.cc b/src/analyzer/protocol/finger/Finger.cc index 97835237b1..155a1bc14b 100644 --- a/src/analyzer/protocol/finger/Finger.cc +++ b/src/analyzer/protocol/finger/Finger.cc @@ -2,13 +2,14 @@ #include "zeek/analyzer/protocol/finger/Finger.h" +#include "zeek/zeek-config.h" + #include #include "zeek/Event.h" #include "zeek/NetVar.h" #include "zeek/analyzer/protocol/finger/events.bif.h" #include "zeek/analyzer/protocol/tcp/ContentLine.h" -#include "zeek/zeek-config.h" namespace zeek::analyzer::finger { diff --git a/src/analyzer/protocol/ftp/FTP.cc b/src/analyzer/protocol/ftp/FTP.cc index 8cd3e28e2f..6067438431 100644 --- a/src/analyzer/protocol/ftp/FTP.cc +++ b/src/analyzer/protocol/ftp/FTP.cc @@ -2,6 +2,8 @@ #include "zeek/analyzer/protocol/ftp/FTP.h" +#include "zeek/zeek-config.h" + #include #include "zeek/Base64.h" @@ -12,7 +14,6 @@ #include "zeek/analyzer/Manager.h" #include "zeek/analyzer/protocol/ftp/events.bif.h" #include "zeek/analyzer/protocol/login/NVT.h" -#include "zeek/zeek-config.h" namespace zeek::analyzer::ftp { diff --git a/src/analyzer/protocol/gnutella/Gnutella.cc b/src/analyzer/protocol/gnutella/Gnutella.cc index 79eeb9f2c1..4fc37de9f6 100644 --- a/src/analyzer/protocol/gnutella/Gnutella.cc +++ b/src/analyzer/protocol/gnutella/Gnutella.cc @@ -2,6 +2,8 @@ #include "zeek/analyzer/protocol/gnutella/Gnutella.h" +#include "zeek/zeek-config.h" + #include #include @@ -10,7 +12,6 @@ #include "zeek/analyzer/Manager.h" #include "zeek/analyzer/protocol/gnutella/events.bif.h" #include "zeek/analyzer/protocol/pia/PIA.h" -#include "zeek/zeek-config.h" namespace zeek::analyzer::gnutella { diff --git a/src/analyzer/protocol/http/HTTP.cc b/src/analyzer/protocol/http/HTTP.cc index 4e434fae88..02ab9b05c6 100644 --- a/src/analyzer/protocol/http/HTTP.cc +++ b/src/analyzer/protocol/http/HTTP.cc @@ -2,6 +2,8 @@ #include "zeek/analyzer/protocol/http/HTTP.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -13,7 +15,6 @@ #include "zeek/analyzer/protocol/http/events.bif.h" #include "zeek/analyzer/protocol/mime/MIME.h" #include "zeek/file_analysis/Manager.h" -#include "zeek/zeek-config.h" namespace zeek::analyzer::http { diff --git a/src/analyzer/protocol/ident/Ident.cc b/src/analyzer/protocol/ident/Ident.cc index 3fe466b47f..47946d5f8a 100644 --- a/src/analyzer/protocol/ident/Ident.cc +++ b/src/analyzer/protocol/ident/Ident.cc @@ -2,13 +2,14 @@ #include "zeek/analyzer/protocol/ident/Ident.h" +#include "zeek/zeek-config.h" + #include #include "zeek/Event.h" #include "zeek/NetVar.h" #include "zeek/ZeekString.h" #include "zeek/analyzer/protocol/ident/events.bif.h" -#include "zeek/zeek-config.h" namespace zeek::analyzer::ident { diff --git a/src/analyzer/protocol/krb/KRB.h b/src/analyzer/protocol/krb/KRB.h index bb840abaa1..9dad969595 100644 --- a/src/analyzer/protocol/krb/KRB.h +++ b/src/analyzer/protocol/krb/KRB.h @@ -2,10 +2,10 @@ #pragma once -#include - #include "zeek/zeek-config.h" +#include + #ifdef USE_KRB5 #include #endif diff --git a/src/analyzer/protocol/login/Login.cc b/src/analyzer/protocol/login/Login.cc index 509a62be36..8be877acc4 100644 --- a/src/analyzer/protocol/login/Login.cc +++ b/src/analyzer/protocol/login/Login.cc @@ -2,6 +2,8 @@ #include "zeek/analyzer/protocol/login/Login.h" +#include "zeek/zeek-config.h" + #include #include @@ -12,7 +14,6 @@ #include "zeek/Var.h" #include "zeek/ZeekString.h" #include "zeek/analyzer/protocol/login/events.bif.h" -#include "zeek/zeek-config.h" namespace zeek::analyzer::login { diff --git a/src/analyzer/protocol/login/NVT.cc b/src/analyzer/protocol/login/NVT.cc index 06fd52f23f..fc675e2b40 100644 --- a/src/analyzer/protocol/login/NVT.cc +++ b/src/analyzer/protocol/login/NVT.cc @@ -2,6 +2,8 @@ #include "zeek/analyzer/protocol/login/NVT.h" +#include "zeek/zeek-config.h" + #include #include "zeek/Event.h" @@ -10,7 +12,6 @@ #include "zeek/ZeekString.h" #include "zeek/analyzer/protocol/login/events.bif.h" #include "zeek/analyzer/protocol/tcp/TCP.h" -#include "zeek/zeek-config.h" #define IS_3_BYTE_OPTION(c) (c >= 251 && c <= 254) diff --git a/src/analyzer/protocol/login/RSH.cc b/src/analyzer/protocol/login/RSH.cc index 677c0e05bc..35cb65b27d 100644 --- a/src/analyzer/protocol/login/RSH.cc +++ b/src/analyzer/protocol/login/RSH.cc @@ -2,11 +2,12 @@ #include "zeek/analyzer/protocol/login/RSH.h" +#include "zeek/zeek-config.h" + #include "zeek/Event.h" #include "zeek/NetVar.h" #include "zeek/Reporter.h" #include "zeek/analyzer/protocol/login/events.bif.h" -#include "zeek/zeek-config.h" namespace zeek::analyzer::login { diff --git a/src/analyzer/protocol/login/Rlogin.cc b/src/analyzer/protocol/login/Rlogin.cc index ee2a9d5c71..7543a437f6 100644 --- a/src/analyzer/protocol/login/Rlogin.cc +++ b/src/analyzer/protocol/login/Rlogin.cc @@ -2,11 +2,12 @@ #include "zeek/analyzer/protocol/login/Rlogin.h" +#include "zeek/zeek-config.h" + #include "zeek/Event.h" #include "zeek/NetVar.h" #include "zeek/Reporter.h" #include "zeek/analyzer/protocol/login/events.bif.h" -#include "zeek/zeek-config.h" namespace zeek::analyzer::login { diff --git a/src/analyzer/protocol/login/Telnet.cc b/src/analyzer/protocol/login/Telnet.cc index 4d3c8275f0..8c0d23a8d8 100644 --- a/src/analyzer/protocol/login/Telnet.cc +++ b/src/analyzer/protocol/login/Telnet.cc @@ -2,9 +2,10 @@ #include "zeek/analyzer/protocol/login/Telnet.h" +#include "zeek/zeek-config.h" + #include "zeek/analyzer/protocol/login/NVT.h" #include "zeek/analyzer/protocol/login/events.bif.h" -#include "zeek/zeek-config.h" namespace zeek::analyzer::login { diff --git a/src/analyzer/protocol/mime/MIME.cc b/src/analyzer/protocol/mime/MIME.cc index 2cc4509241..5762803a49 100644 --- a/src/analyzer/protocol/mime/MIME.cc +++ b/src/analyzer/protocol/mime/MIME.cc @@ -1,12 +1,13 @@ #include "zeek/analyzer/protocol/mime/MIME.h" +#include "zeek/zeek-config.h" + #include "zeek/Base64.h" #include "zeek/NetVar.h" #include "zeek/Reporter.h" #include "zeek/analyzer/protocol/mime/events.bif.h" #include "zeek/digest.h" #include "zeek/file_analysis/Manager.h" -#include "zeek/zeek-config.h" // Here are a few things to do: // diff --git a/src/analyzer/protocol/ncp/NCP.cc b/src/analyzer/protocol/ncp/NCP.cc index 621ac30af5..89b961883d 100644 --- a/src/analyzer/protocol/ncp/NCP.cc +++ b/src/analyzer/protocol/ncp/NCP.cc @@ -2,13 +2,14 @@ #include "zeek/analyzer/protocol/ncp/NCP.h" +#include "zeek/zeek-config.h" + #include #include #include #include "zeek/analyzer/protocol/ncp/consts.bif.h" #include "zeek/analyzer/protocol/ncp/events.bif.h" -#include "zeek/zeek-config.h" using namespace std; diff --git a/src/analyzer/protocol/netbios/NetbiosSSN.cc b/src/analyzer/protocol/netbios/NetbiosSSN.cc index 8c5c9b2d07..18efafa742 100644 --- a/src/analyzer/protocol/netbios/NetbiosSSN.cc +++ b/src/analyzer/protocol/netbios/NetbiosSSN.cc @@ -2,6 +2,8 @@ #include "zeek/analyzer/protocol/netbios/NetbiosSSN.h" +#include "zeek/zeek-config.h" + #include #include "zeek/Event.h" @@ -10,7 +12,6 @@ #include "zeek/ZeekString.h" #include "zeek/analyzer/protocol/netbios/events.bif.h" #include "zeek/session/Manager.h" -#include "zeek/zeek-config.h" constexpr double netbios_ssn_session_timeout = 15.0; diff --git a/src/analyzer/protocol/pop3/POP3.cc b/src/analyzer/protocol/pop3/POP3.cc index c562e22c92..9cffe3b2e1 100644 --- a/src/analyzer/protocol/pop3/POP3.cc +++ b/src/analyzer/protocol/pop3/POP3.cc @@ -3,6 +3,8 @@ #include "zeek/analyzer/protocol/pop3/POP3.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -11,7 +13,6 @@ #include "zeek/Reporter.h" #include "zeek/analyzer/Manager.h" #include "zeek/analyzer/protocol/pop3/events.bif.h" -#include "zeek/zeek-config.h" namespace zeek::analyzer::pop3 { diff --git a/src/analyzer/protocol/rpc/MOUNT.cc b/src/analyzer/protocol/rpc/MOUNT.cc index de6d307220..ed05293ad5 100644 --- a/src/analyzer/protocol/rpc/MOUNT.cc +++ b/src/analyzer/protocol/rpc/MOUNT.cc @@ -2,6 +2,8 @@ #include "zeek/analyzer/protocol/rpc/MOUNT.h" +#include "zeek/zeek-config.h" + #include #include @@ -10,7 +12,6 @@ #include "zeek/ZeekString.h" #include "zeek/analyzer/protocol/rpc/XDR.h" #include "zeek/analyzer/protocol/rpc/events.bif.h" -#include "zeek/zeek-config.h" namespace zeek::analyzer::rpc { diff --git a/src/analyzer/protocol/rpc/NFS.cc b/src/analyzer/protocol/rpc/NFS.cc index d915a5b7b6..89ea8834d2 100644 --- a/src/analyzer/protocol/rpc/NFS.cc +++ b/src/analyzer/protocol/rpc/NFS.cc @@ -2,6 +2,8 @@ #include "zeek/analyzer/protocol/rpc/NFS.h" +#include "zeek/zeek-config.h" + #include #include @@ -10,7 +12,6 @@ #include "zeek/ZeekString.h" #include "zeek/analyzer/protocol/rpc/XDR.h" #include "zeek/analyzer/protocol/rpc/events.bif.h" -#include "zeek/zeek-config.h" namespace zeek::analyzer::rpc { diff --git a/src/analyzer/protocol/rpc/Portmap.cc b/src/analyzer/protocol/rpc/Portmap.cc index 82f6df675a..eee978812d 100644 --- a/src/analyzer/protocol/rpc/Portmap.cc +++ b/src/analyzer/protocol/rpc/Portmap.cc @@ -2,11 +2,12 @@ #include "zeek/analyzer/protocol/rpc/Portmap.h" +#include "zeek/zeek-config.h" + #include "zeek/Event.h" #include "zeek/NetVar.h" #include "zeek/analyzer/protocol/rpc/XDR.h" #include "zeek/analyzer/protocol/rpc/events.bif.h" -#include "zeek/zeek-config.h" #define PMAPPROC_NULL 0 #define PMAPPROC_SET 1 diff --git a/src/analyzer/protocol/rpc/RPC.cc b/src/analyzer/protocol/rpc/RPC.cc index 9a8fe56aa9..735fc95a19 100644 --- a/src/analyzer/protocol/rpc/RPC.cc +++ b/src/analyzer/protocol/rpc/RPC.cc @@ -2,6 +2,8 @@ #include "zeek/analyzer/protocol/rpc/RPC.h" +#include "zeek/zeek-config.h" + #include #include @@ -11,7 +13,6 @@ #include "zeek/analyzer/protocol/rpc/XDR.h" #include "zeek/analyzer/protocol/rpc/events.bif.h" #include "zeek/session/Manager.h" -#include "zeek/zeek-config.h" namespace { // local namespace diff --git a/src/analyzer/protocol/rpc/XDR.cc b/src/analyzer/protocol/rpc/XDR.cc index e902305464..dddae9b154 100644 --- a/src/analyzer/protocol/rpc/XDR.cc +++ b/src/analyzer/protocol/rpc/XDR.cc @@ -2,11 +2,12 @@ #include "zeek/analyzer/protocol/rpc/XDR.h" +#include "zeek/zeek-config.h" + #include #include #include "zeek/analyzer/protocol/rpc/events.bif.h" -#include "zeek/zeek-config.h" uint32_t zeek::analyzer::rpc::extract_XDR_uint32(const u_char*& buf, int& len) { diff --git a/src/analyzer/protocol/smtp/SMTP.cc b/src/analyzer/protocol/smtp/SMTP.cc index c83397662a..2d1d9a7fe6 100644 --- a/src/analyzer/protocol/smtp/SMTP.cc +++ b/src/analyzer/protocol/smtp/SMTP.cc @@ -2,6 +2,8 @@ #include "zeek/analyzer/protocol/smtp/SMTP.h" +#include "zeek/zeek-config.h" + #include #include "zeek/Event.h" @@ -9,7 +11,6 @@ #include "zeek/Reporter.h" #include "zeek/analyzer/Manager.h" #include "zeek/analyzer/protocol/smtp/events.bif.h" -#include "zeek/zeek-config.h" #undef SMTP_CMD_DEF #define SMTP_CMD_DEF(cmd) #cmd, diff --git a/src/analyzer/protocol/zip/ZIP.h b/src/analyzer/protocol/zip/ZIP.h index 5ec76f502f..6b4477fc2b 100644 --- a/src/analyzer/protocol/zip/ZIP.h +++ b/src/analyzer/protocol/zip/ZIP.h @@ -2,10 +2,11 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include "zeek/analyzer/protocol/tcp/TCP.h" -#include "zeek/zeek-config.h" namespace zeek::analyzer::zip { diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index d8119a4be8..bf11f840ff 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -1176,7 +1176,7 @@ void Manager::ProcessStoreEventInsertUpdate(const TableValPtr& table, const std: { reporter->Error( "ProcessStoreEvent %s: could not convert key \"%s\" for store \"%s\" while receiving " - "remote data. This probably means the tables have different types on different nodes.", + "remote data. This probably means the tables have different types on different nodes.", type, to_string(key).c_str(), store_id.c_str()); return; } diff --git a/src/file_analysis/Component.h b/src/file_analysis/Component.h index 986707c7d9..b6f75bc247 100644 --- a/src/file_analysis/Component.h +++ b/src/file_analysis/Component.h @@ -2,10 +2,11 @@ #pragma once +#include "zeek/zeek-config.h" + #include "zeek/file_analysis/Tag.h" #include "zeek/plugin/Component.h" #include "zeek/plugin/TaggedComponent.h" -#include "zeek/zeek-config.h" namespace zeek { diff --git a/src/file_analysis/Tag.h b/src/file_analysis/Tag.h index cf3b4ac5ce..59ce6f54b5 100644 --- a/src/file_analysis/Tag.h +++ b/src/file_analysis/Tag.h @@ -2,9 +2,10 @@ #pragma once -#include "zeek/Tag.h" #include "zeek/zeek-config.h" +#include "zeek/Tag.h" + namespace zeek::plugin { template class TaggedComponent; diff --git a/src/input/Tag.h b/src/input/Tag.h index a58a583a6b..f62a38bc65 100644 --- a/src/input/Tag.h +++ b/src/input/Tag.h @@ -2,9 +2,10 @@ #pragma once -#include "zeek/Tag.h" #include "zeek/zeek-config.h" +#include "zeek/Tag.h" + namespace zeek { diff --git a/src/input/readers/sqlite/SQLite.cc b/src/input/readers/sqlite/SQLite.cc index 20a2baf3a7..ebc1c52b5a 100644 --- a/src/input/readers/sqlite/SQLite.cc +++ b/src/input/readers/sqlite/SQLite.cc @@ -2,6 +2,8 @@ #include "zeek/input/readers/sqlite/SQLite.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -12,7 +14,6 @@ #include "zeek/logging/writers/ascii/ascii.bif.h" #include "zeek/logging/writers/sqlite/sqlite.bif.h" #include "zeek/threading/SerialTypes.h" -#include "zeek/zeek-config.h" using zeek::threading::Field; using zeek::threading::Value; diff --git a/src/input/readers/sqlite/SQLite.h b/src/input/readers/sqlite/SQLite.h index f768db35a3..797d09ac41 100644 --- a/src/input/readers/sqlite/SQLite.h +++ b/src/input/readers/sqlite/SQLite.h @@ -2,13 +2,14 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include #include "zeek/3rdparty/sqlite3.h" #include "zeek/input/ReaderBackend.h" #include "zeek/threading/formatters/Ascii.h" -#include "zeek/zeek-config.h" namespace zeek::input::reader::detail { diff --git a/src/iosource/BPF_Program.cc b/src/iosource/BPF_Program.cc index 4607822197..13f15e14d8 100644 --- a/src/iosource/BPF_Program.cc +++ b/src/iosource/BPF_Program.cc @@ -2,10 +2,10 @@ #include "zeek/iosource/BPF_Program.h" -#include - #include "zeek/zeek-config.h" +#include + #ifdef DONT_HAVE_LIBPCAP_PCAP_FREECODE extern "C" { diff --git a/src/iosource/Manager.h b/src/iosource/Manager.h index d2caa8a777..cb8af3fe4c 100644 --- a/src/iosource/Manager.h +++ b/src/iosource/Manager.h @@ -2,13 +2,14 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include #include #include "zeek/Flare.h" #include "zeek/iosource/IOSource.h" -#include "zeek/zeek-config.h" struct timespec; struct kevent; diff --git a/src/iosource/Packet.h b/src/iosource/Packet.h index 29b516c755..5145724a08 100644 --- a/src/iosource/Packet.h +++ b/src/iosource/Packet.h @@ -1,11 +1,11 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include // for u_char #include -#include "zeek/zeek-config.h" - #if defined(__OpenBSD__) #include typedef struct bpf_timeval pkt_timeval; diff --git a/src/iosource/PktDumper.cc b/src/iosource/PktDumper.cc index fd0794483e..ec65615267 100644 --- a/src/iosource/PktDumper.cc +++ b/src/iosource/PktDumper.cc @@ -3,9 +3,10 @@ #include "zeek/iosource/PktDumper.h" -#include "zeek/DebugLogger.h" #include "zeek/zeek-config.h" +#include "zeek/DebugLogger.h" + namespace zeek::iosource { diff --git a/src/iosource/PktDumper.h b/src/iosource/PktDumper.h index 9e18fd8386..c39895e405 100644 --- a/src/iosource/PktDumper.h +++ b/src/iosource/PktDumper.h @@ -2,10 +2,10 @@ #pragma once -#include - #include "zeek/zeek-config.h" +#include + namespace zeek { diff --git a/src/iosource/PktSrc.cc b/src/iosource/PktSrc.cc index 79f042512a..663fec53ad 100644 --- a/src/iosource/PktSrc.cc +++ b/src/iosource/PktSrc.cc @@ -2,6 +2,8 @@ #include "zeek/iosource/PktSrc.h" +#include "zeek/zeek-config.h" + #include #include "zeek/Hash.h" @@ -13,7 +15,6 @@ #include "zeek/packet_analysis/Manager.h" #include "zeek/session/Manager.h" #include "zeek/util.h" -#include "zeek/zeek-config.h" namespace zeek::iosource { diff --git a/src/logging/Tag.h b/src/logging/Tag.h index 3b879ed3e8..e9ed93c03b 100644 --- a/src/logging/Tag.h +++ b/src/logging/Tag.h @@ -2,9 +2,10 @@ #pragma once -#include "zeek/Tag.h" #include "zeek/zeek-config.h" +#include "zeek/Tag.h" + namespace zeek { diff --git a/src/logging/writers/sqlite/SQLite.cc b/src/logging/writers/sqlite/SQLite.cc index 4ec1a23f3c..6bdaf718fa 100644 --- a/src/logging/writers/sqlite/SQLite.cc +++ b/src/logging/writers/sqlite/SQLite.cc @@ -2,13 +2,14 @@ #include "zeek/logging/writers/sqlite/SQLite.h" +#include "zeek/zeek-config.h" + #include #include #include #include "zeek/logging/writers/sqlite/sqlite.bif.h" #include "zeek/threading/SerialTypes.h" -#include "zeek/zeek-config.h" using namespace std; using zeek::threading::Field; diff --git a/src/logging/writers/sqlite/SQLite.h b/src/logging/writers/sqlite/SQLite.h index 06462a1e20..be4dcd6e97 100644 --- a/src/logging/writers/sqlite/SQLite.h +++ b/src/logging/writers/sqlite/SQLite.h @@ -4,11 +4,12 @@ #pragma once +#include "zeek/zeek-config.h" + #include "zeek/3rdparty/sqlite3.h" #include "zeek/Desc.h" #include "zeek/logging/WriterBackend.h" #include "zeek/threading/formatters/Ascii.h" -#include "zeek/zeek-config.h" namespace zeek::logging::writer::detail { diff --git a/src/main.cc b/src/main.cc index fdaf43e877..254fb14c58 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,9 +1,10 @@ // See the file "COPYING" in the main distribution directory for copyright. +#include "zeek/zeek-config.h" + #include "zeek/RunState.h" #include "zeek/iosource/Manager.h" #include "zeek/supervisor/Supervisor.h" -#include "zeek/zeek-config.h" #include "zeek/zeek-setup.h" int main(int argc, char** argv) diff --git a/src/net_util.cc b/src/net_util.cc index bdbe6bd1fb..7fc4084eea 100644 --- a/src/net_util.cc +++ b/src/net_util.cc @@ -2,6 +2,8 @@ #include "zeek/net_util.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -10,7 +12,6 @@ #include "zeek/IP.h" #include "zeek/IPAddr.h" #include "zeek/Reporter.h" -#include "zeek/zeek-config.h" const char* transport_proto_string(TransportProto proto) { diff --git a/src/packet_analysis/Component.h b/src/packet_analysis/Component.h index a31a1b3c58..c58525e293 100644 --- a/src/packet_analysis/Component.h +++ b/src/packet_analysis/Component.h @@ -2,13 +2,14 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include "zeek/packet_analysis/Tag.h" #include "zeek/plugin/Component.h" #include "zeek/plugin/TaggedComponent.h" #include "zeek/util.h" -#include "zeek/zeek-config.h" namespace zeek::packet_analysis { diff --git a/src/packet_analysis/Tag.h b/src/packet_analysis/Tag.h index 05bcdbb555..8feb482c06 100644 --- a/src/packet_analysis/Tag.h +++ b/src/packet_analysis/Tag.h @@ -2,9 +2,10 @@ #pragma once -#include "zeek/Tag.h" #include "zeek/zeek-config.h" +#include "zeek/Tag.h" + namespace zeek::plugin { template class TaggedComponent; diff --git a/src/plugin/Component.h b/src/plugin/Component.h index 44e61d4430..bb9b585f5b 100644 --- a/src/plugin/Component.h +++ b/src/plugin/Component.h @@ -2,10 +2,10 @@ #pragma once -#include - #include "zeek/zeek-config.h" +#include + namespace zeek { diff --git a/src/plugin/Plugin.h b/src/plugin/Plugin.h index 615e7c30d9..ac21e99645 100644 --- a/src/plugin/Plugin.h +++ b/src/plugin/Plugin.h @@ -2,13 +2,14 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include #include #include "zeek/ZeekArgs.h" #include "zeek/logging/WriterBackend.h" -#include "zeek/zeek-config.h" // Increase this when making incompatible changes to the plugin API. Note // that the constant is never used in C code. It's picked up on by CMake. diff --git a/src/probabilistic/BloomFilter.h b/src/probabilistic/BloomFilter.h index 4ab3079f55..c67b6674c5 100644 --- a/src/probabilistic/BloomFilter.h +++ b/src/probabilistic/BloomFilter.h @@ -2,6 +2,8 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include #include @@ -9,7 +11,6 @@ #include "zeek/probabilistic/BitVector.h" #include "zeek/probabilistic/Hasher.h" -#include "zeek/zeek-config.h" namespace broker { diff --git a/src/probabilistic/CounterVector.h b/src/probabilistic/CounterVector.h index cdd61c5089..0f43b20582 100644 --- a/src/probabilistic/CounterVector.h +++ b/src/probabilistic/CounterVector.h @@ -2,13 +2,13 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include #include #include -#include "zeek/zeek-config.h" - namespace broker { class data; diff --git a/src/session/Manager.cc b/src/session/Manager.cc index cc5805b439..47f5b7d239 100644 --- a/src/session/Manager.cc +++ b/src/session/Manager.cc @@ -2,6 +2,8 @@ #include "zeek/session/Manager.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -21,7 +23,6 @@ #include "zeek/packet_analysis/Manager.h" #include "zeek/session/Session.h" #include "zeek/telemetry/Manager.h" -#include "zeek/zeek-config.h" zeek::session::Manager* zeek::session_mgr = nullptr; zeek::session::Manager*& zeek::sessions = zeek::session_mgr; diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index b50477f2fc..ab905f4ade 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -2,6 +2,8 @@ #include "zeek/supervisor/Supervisor.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -14,8 +16,6 @@ #include #include -#include "zeek/zeek-config.h" - #define RAPIDJSON_HAS_STDSTRING 1 #include diff --git a/src/threading/BasicThread.cc b/src/threading/BasicThread.cc index 1df400bbdb..8385c5264f 100644 --- a/src/threading/BasicThread.cc +++ b/src/threading/BasicThread.cc @@ -1,11 +1,12 @@ #include "zeek/threading/BasicThread.h" +#include "zeek/zeek-config.h" + #include #include #include "zeek/threading/Manager.h" #include "zeek/util.h" -#include "zeek/zeek-config.h" namespace zeek::threading { diff --git a/src/threading/BasicThread.h b/src/threading/BasicThread.h index 576ee3c084..f009a457df 100644 --- a/src/threading/BasicThread.h +++ b/src/threading/BasicThread.h @@ -1,12 +1,12 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include #include -#include "zeek/zeek-config.h" - namespace zeek::threading { diff --git a/src/threading/Formatter.cc b/src/threading/Formatter.cc index 0a63431354..680a4ece4c 100644 --- a/src/threading/Formatter.cc +++ b/src/threading/Formatter.cc @@ -2,11 +2,12 @@ #include "zeek/threading/Formatter.h" +#include "zeek/zeek-config.h" + #include #include "zeek/bro_inet_ntop.h" #include "zeek/threading/MsgThread.h" -#include "zeek/zeek-config.h" using zeek::threading::Field; using zeek::threading::Value; diff --git a/src/threading/formatters/Ascii.cc b/src/threading/formatters/Ascii.cc index 70d3a574ee..9663ec560e 100644 --- a/src/threading/formatters/Ascii.cc +++ b/src/threading/formatters/Ascii.cc @@ -2,12 +2,13 @@ #include "threading/formatters/Ascii.h" +#include "zeek/zeek-config.h" + #include #include #include "zeek/Desc.h" #include "zeek/threading/MsgThread.h" -#include "zeek/zeek-config.h" using namespace std; diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index 745ddf9c0c..07671948b1 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -2,6 +2,8 @@ #include "zeek/zeek-setup.h" +#include "zeek/zeek-config.h" + #include #include #include @@ -14,7 +16,6 @@ #include #include "zeek/3rdparty/sqlite3.h" -#include "zeek/zeek-config.h" #define DOCTEST_CONFIG_IMPLEMENT #include "zeek/3rdparty/doctest.h" diff --git a/src/zeekygen/ScriptInfo.h b/src/zeekygen/ScriptInfo.h index 024bc31ed0..1042c51239 100644 --- a/src/zeekygen/ScriptInfo.h +++ b/src/zeekygen/ScriptInfo.h @@ -2,6 +2,8 @@ #pragma once +#include "zeek/zeek-config.h" + #include // for time_t #include #include @@ -9,7 +11,6 @@ #include #include -#include "zeek/zeek-config.h" #include "zeek/zeekygen/Info.h" namespace zeek::zeekygen::detail diff --git a/src/zeekygen/Target.h b/src/zeekygen/Target.h index c681e87027..1008cc4fe2 100644 --- a/src/zeekygen/Target.h +++ b/src/zeekygen/Target.h @@ -2,13 +2,13 @@ #pragma once +#include "zeek/zeek-config.h" + #include #include #include #include -#include "zeek/zeek-config.h" - namespace zeek::zeekygen::detail { diff --git a/src/zeekygen/utils.h b/src/zeekygen/utils.h index 198e136ef8..ebcc2b9095 100644 --- a/src/zeekygen/utils.h +++ b/src/zeekygen/utils.h @@ -2,12 +2,12 @@ #pragma once +#include "zeek/zeek-config.h" + #include // for time_t #include #include -#include "zeek/zeek-config.h" - namespace zeek::detail { class ID; From 07e276ab2e351ce71b709139f1933b9ead40d094 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Fri, 24 Sep 2021 14:36:54 -0700 Subject: [PATCH 2/7] clang-format: A few minor comment-spacing fixes --- src/Dict.cc | 4 ++-- src/analyzer/protocol/rpc/RPC.cc | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Dict.cc b/src/Dict.cc index 7f2cc2d7a8..3be737328a 100644 --- a/src/Dict.cc +++ b/src/Dict.cc @@ -1239,7 +1239,7 @@ void Dictionary::InsertRelocateAndAdjust(detail::DictEntry& entry, int insert_po // range if the changed range straddles over remap_end. if ( Remapping() && insert_position <= remap_end && remap_end < last_affected_position ) { //[i,j] range changed. if map_end in between. then possibly old entry pushed down across - //map_end. + // map_end. remap_end = last_affected_position; // adjust to j on the conservative side. } @@ -1498,7 +1498,7 @@ void Dictionary::Remap() if ( ! table[remap_end].Empty() && Remap(remap_end) ) left--; else //< successful Remap may increase remap_end in the case of SizeUp due to insert. if so, - //remap_end need to be worked on again. + // remap_end need to be worked on again. remap_end--; } if ( remap_end < 0 ) diff --git a/src/analyzer/protocol/rpc/RPC.cc b/src/analyzer/protocol/rpc/RPC.cc index 735fc95a19..f06d996313 100644 --- a/src/analyzer/protocol/rpc/RPC.cc +++ b/src/analyzer/protocol/rpc/RPC.cc @@ -658,8 +658,9 @@ void Contents_RPC::DeliverStream(int len, const u_char* data, bool orig) last_frag = (marker & 0x80000000) != 0; marker &= 0x7fffffff; // printf("%.6f %d marker= %u <> last_frag= %d <> expected=%llu <> - // processed= %llu <> len = %d\n", run_state::network_time, IsOrig(), marker, - //last_frag, msg_buf.GetExpected(), msg_buf.GetProcessed(), len); + // processed= %llu <> len = %d\n", run_state::network_time, IsOrig(), + // marker, + // last_frag, msg_buf.GetExpected(), msg_buf.GetProcessed(), len); if ( ! msg_buf.AddToExpected(marker) ) Conn()->Weird("RPC_message_too_long", From cb99ae2b7c9988656b097ad2789dffd2c0c37939 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Fri, 24 Sep 2021 14:56:57 -0700 Subject: [PATCH 3/7] clang-format: Enforce ordering of includes in ZBody --- .clang-format | 2 +- src/script_opt/ZAM/ZBody.cc | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.clang-format b/.clang-format index 14203ffdc7..394707c91a 100644 --- a/.clang-format +++ b/.clang-format @@ -30,7 +30,7 @@ BreakBeforeBraces: Whitesmiths # SplitEmptyNamespace: false AccessModifierOffset: -4 -AlignAfterOpenBracket: true +AlignAfterOpenBracket: Align AlignTrailingComments: false AllowShortBlocksOnASingleLine: Empty AllowShortEnumsOnASingleLine: true diff --git a/src/script_opt/ZAM/ZBody.cc b/src/script_opt/ZAM/ZBody.cc index b58960ad36..aa6efde064 100644 --- a/src/script_opt/ZAM/ZBody.cc +++ b/src/script_opt/ZAM/ZBody.cc @@ -313,9 +313,11 @@ ValPtr ZBody::DoExec(Frame* f, int start_pc, StmtFlowType& flow) case OP_NOP: break; -// These must stay in this order or the build fails. + // These must stay in this order or the build fails. + // clang-format off #include "ZAM-EvalMacros.h" #include "ZAM-EvalDefs.h" + // clang-format on default: reporter->InternalError("bad ZAM opcode"); From e97c14add5b04aedc7f3f9dba59f665cbad793af Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Fri, 24 Sep 2021 14:57:22 -0700 Subject: [PATCH 4/7] clang-format: Other include ordering changes --- src/IP.h | 4 +++- src/iosource/Manager.cc | 4 ++++ src/packet_analysis/protocol/arp/ARP.h | 2 ++ src/script_opt/IDOptInfo.h | 4 ++-- src/zeek-affinity.cc | 2 ++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/IP.h b/src/IP.h index 8aebb72d92..3c2fbef813 100644 --- a/src/IP.h +++ b/src/IP.h @@ -4,9 +4,11 @@ #include "zeek/zeek-config.h" +// clang-format off +#include // for u_char #include #include -#include // for u_char +// clang-format on #ifdef HAVE_NETINET_IP6_H #include diff --git a/src/iosource/Manager.cc b/src/iosource/Manager.cc index d0065ab476..8f669512fa 100644 --- a/src/iosource/Manager.cc +++ b/src/iosource/Manager.cc @@ -3,8 +3,12 @@ #include "zeek/iosource/Manager.h" #include +// These two files have to remain in the same order or FreeBSD builds +// stop working. +// clang-format off #include #include +// clang-format on #include #include diff --git a/src/packet_analysis/protocol/arp/ARP.h b/src/packet_analysis/protocol/arp/ARP.h index 0aa8ebbac0..4adad42347 100644 --- a/src/packet_analysis/protocol/arp/ARP.h +++ b/src/packet_analysis/protocol/arp/ARP.h @@ -2,9 +2,11 @@ #pragma once +// clang-format off #include #include #include +// clang-format on #include "zeek/packet_analysis/Analyzer.h" #include "zeek/packet_analysis/Component.h" diff --git a/src/script_opt/IDOptInfo.h b/src/script_opt/IDOptInfo.h index 732958a7f8..ada590e2bd 100644 --- a/src/script_opt/IDOptInfo.h +++ b/src/script_opt/IDOptInfo.h @@ -7,9 +7,9 @@ #include -#include "zeek/IntrusivePtr.h" -#include "zeek/ID.h" #include "zeek/Expr.h" +#include "zeek/ID.h" +#include "zeek/IntrusivePtr.h" namespace zeek::detail { diff --git a/src/zeek-affinity.cc b/src/zeek-affinity.cc index c002181286..f43ea99088 100644 --- a/src/zeek-affinity.cc +++ b/src/zeek-affinity.cc @@ -28,8 +28,10 @@ bool set_affinity(int core_number) #elif defined(__FreeBSD__) +// clang-format off #include #include +// clang-format on namespace zeek { From 02206f3215f977ba7752476ba89ca06abe93375c Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Fri, 24 Sep 2021 14:57:56 -0700 Subject: [PATCH 5/7] clang-format: Other minor formatting changes --- src/analyzer/protocol/pia/PIA.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/analyzer/protocol/pia/PIA.cc b/src/analyzer/protocol/pia/PIA.cc index dcb6cb14b4..93a4cbc677 100644 --- a/src/analyzer/protocol/pia/PIA.cc +++ b/src/analyzer/protocol/pia/PIA.cc @@ -106,9 +106,9 @@ void PIA::PIA_DeliverPacket(int len, const u_char* data, bool is_orig, uint64_t if ( (pkt_buffer.state == BUFFERING || new_state == BUFFERING) && len > 0 ) { AddToBuffer(&pkt_buffer, seq, len, data, is_orig, ip); - if ( pkt_buffer.size > zeek::detail::dpd_buffer_size || ++pkt_buffer.chunks > zeek::detail::dpd_max_packets ) - new_state = zeek::detail::dpd_match_only_beginning ? - SKIPPING : MATCHING_ONLY; + if ( pkt_buffer.size > zeek::detail::dpd_buffer_size || + ++pkt_buffer.chunks > zeek::detail::dpd_max_packets ) + new_state = zeek::detail::dpd_match_only_beginning ? SKIPPING : MATCHING_ONLY; } // FIXME: I'm not sure why it does not work with eol=true... @@ -280,9 +280,9 @@ void PIA_TCP::DeliverStream(int len, const u_char* data, bool is_orig) if ( stream_buffer.state == BUFFERING || new_state == BUFFERING ) { AddToBuffer(&stream_buffer, len, data, is_orig); - if ( stream_buffer.size > zeek::detail::dpd_buffer_size || ++stream_buffer.chunks > zeek::detail::dpd_max_packets ) - new_state = zeek::detail::dpd_match_only_beginning ? - SKIPPING : MATCHING_ONLY; + if ( stream_buffer.size > zeek::detail::dpd_buffer_size || + ++stream_buffer.chunks > zeek::detail::dpd_max_packets ) + new_state = zeek::detail::dpd_match_only_beginning ? SKIPPING : MATCHING_ONLY; } DoMatch(data, len, is_orig, false, false, false, nullptr); From 4423574d265749da8e707ab0fbcffcbfaed26614 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Fri, 24 Sep 2021 15:40:37 -0700 Subject: [PATCH 6/7] clang-format: Set IndentCaseBlocks to false --- .clang-format | 2 +- src/Attr.cc | 559 +++++---- src/CompHash.cc | 1099 ++++++++--------- src/DbgBreakpoint.cc | 20 +- src/Expr.cc | 240 ++-- src/Func.cc | 35 +- src/IP.cc | 600 +++++---- src/RuleMatcher.cc | 50 +- src/Stmt.cc | 44 +- src/Trigger.cc | 18 +- src/Type.cc | 583 +++++---- src/Val.cc | 336 ++--- src/Var.cc | 20 +- .../protocol/bittorrent/BitTorrentTracker.cc | 319 +++-- src/analyzer/protocol/dns/DNS.cc | 358 +++--- src/analyzer/protocol/http/HTTP.cc | 69 +- src/analyzer/protocol/irc/IRC.cc | 62 +- src/analyzer/protocol/login/NVT.cc | 33 +- src/analyzer/protocol/pop3/POP3.cc | 108 +- src/analyzer/protocol/rpc/Portmap.cc | 48 +- src/analyzer/protocol/rpc/RPC.cc | 102 +- src/broker/Data.cc | 360 +++--- src/broker/Manager.cc | 26 +- src/broker/Store.cc | 9 +- src/file_analysis/analyzer/x509/X509.cc | 46 +- src/input/Manager.cc | 453 ++++--- src/input/readers/ascii/Ascii.cc | 76 +- src/input/readers/benchmark/Benchmark.cc | 20 +- src/input/readers/binary/Binary.cc | 24 +- src/input/readers/config/Config.cc | 72 +- src/input/readers/raw/Raw.cc | 36 +- src/input/readers/sqlite/SQLite.cc | 126 +- src/logging/Manager.cc | 124 +- src/logging/writers/sqlite/SQLite.cc | 100 +- src/packet_analysis/protocol/arp/ARP.cc | 40 +- src/packet_analysis/protocol/icmp/ICMP.cc | 56 +- .../protocol/wrapper/Wrapper.cc | 62 +- src/plugin/Plugin.cc | 84 +- src/script_opt/CPP/Consts.cc | 30 +- src/script_opt/CPP/Inits.cc | 32 +- src/script_opt/CPP/RuntimeVec.cc | 62 +- src/script_opt/CPP/Stmts.cc | 24 +- src/script_opt/CPP/Types.cc | 20 +- src/script_opt/Expr.cc | 102 +- src/script_opt/GenIDDefs.cc | 328 ++--- src/script_opt/ProfileFunc.cc | 498 ++++---- src/script_opt/Reduce.cc | 194 +-- src/script_opt/UseDefs.cc | 356 +++--- src/script_opt/ZAM/AM-Opt.cc | 112 +- src/script_opt/ZAM/Expr.cc | 78 +- src/script_opt/ZAM/Gen-ZAM.cc | 10 +- src/script_opt/ZAM/Stmt.cc | 60 +- src/threading/SerialTypes.cc | 596 ++++----- src/threading/formatters/Ascii.cc | 312 ++--- src/threading/formatters/JSON.cc | 109 +- src/util.cc | 86 +- src/zeekygen/Target.cc | 45 +- src/zeekygen/utils.cc | 22 +- 58 files changed, 4729 insertions(+), 4766 deletions(-) diff --git a/.clang-format b/.clang-format index 394707c91a..79910187b2 100644 --- a/.clang-format +++ b/.clang-format @@ -47,7 +47,7 @@ ColumnLimit: 100 ConstructorInitializerAllOnOneLineOrOnePerLine: false FixNamespaceComments: false IndentCaseLabels: true -IndentCaseBlocks: true +IndentCaseBlocks: false IndentExternBlock: NoIndent IndentPPDirectives: None IndentWidth: 4 diff --git a/src/Attr.cc b/src/Attr.cc index d5a25cfc1e..b0d2947a00 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -317,58 +317,96 @@ void Attributes::CheckAttr(Attr* a) case ATTR_ADD_FUNC: case ATTR_DEL_FUNC: + { + bool is_add = a->Tag() == ATTR_ADD_FUNC; + + const auto& at = a->GetExpr()->GetType(); + if ( at->Tag() != TYPE_FUNC ) { - bool is_add = a->Tag() == ATTR_ADD_FUNC; - - const auto& at = a->GetExpr()->GetType(); - if ( at->Tag() != TYPE_FUNC ) - { - a->GetExpr()->Error(is_add ? "&add_func must be a function" - : "&delete_func must be a function"); - break; - } - - FuncType* aft = at->AsFuncType(); - if ( ! same_type(aft->Yield(), type) ) - { - a->GetExpr()->Error( - is_add ? "&add_func function must yield same type as variable" - : "&delete_func function must yield same type as variable"); - break; - } + a->GetExpr()->Error(is_add ? "&add_func must be a function" + : "&delete_func must be a function"); + break; } + + FuncType* aft = at->AsFuncType(); + if ( ! same_type(aft->Yield(), type) ) + { + a->GetExpr()->Error(is_add + ? "&add_func function must yield same type as variable" + : "&delete_func function must yield same type as variable"); + break; + } + } break; case ATTR_DEFAULT: + { + // &default is allowed for global tables, since it's used in initialization + // of table fields. it's not allowed otherwise. + if ( global_var && ! type->IsTable() ) { - // &default is allowed for global tables, since it's used in initialization - // of table fields. it's not allowed otherwise. - if ( global_var && ! type->IsTable() ) + Error("&default is not valid for global variables except for tables"); + break; + } + + const auto& atype = a->GetExpr()->GetType(); + + if ( type->Tag() != TYPE_TABLE || (type->IsSet() && ! in_record) ) + { + if ( same_type(atype, type) ) + // Ok. + break; + + // Record defaults may be promotable. + if ( (type->Tag() == TYPE_RECORD && atype->Tag() == TYPE_RECORD && + record_promotion_compatible(atype->AsRecordType(), type->AsRecordType())) ) + // Ok. + break; + + if ( type->Tag() == TYPE_TABLE && type->AsTableType()->IsUnspecifiedTable() ) + // Ok. + break; + + auto e = check_and_promote_expr(a->GetExpr(), type); + + if ( e ) { - Error("&default is not valid for global variables except for tables"); + a->SetAttrExpr(std::move(e)); + // Ok. break; } - const auto& atype = a->GetExpr()->GetType(); + a->GetExpr()->Error("&default value has inconsistent type", type.get()); + return; + } - if ( type->Tag() != TYPE_TABLE || (type->IsSet() && ! in_record) ) + TableType* tt = type->AsTableType(); + const auto& ytype = tt->Yield(); + + if ( ! in_record ) + { + // &default applies to the type itself. + if ( ! same_type(atype, ytype) ) { - if ( same_type(atype, type) ) + // It can still be a default function. + if ( atype->Tag() == TYPE_FUNC ) + { + FuncType* f = atype->AsFuncType(); + if ( ! f->CheckArgs(tt->GetIndexTypes()) || ! same_type(f->Yield(), ytype) ) + Error("&default function type clash"); + // Ok. break; + } - // Record defaults may be promotable. - if ( (type->Tag() == TYPE_RECORD && atype->Tag() == TYPE_RECORD && + // Table defaults may be promotable. + if ( (ytype->Tag() == TYPE_RECORD && atype->Tag() == TYPE_RECORD && record_promotion_compatible(atype->AsRecordType(), - type->AsRecordType())) ) + ytype->AsRecordType())) ) // Ok. break; - if ( type->Tag() == TYPE_TABLE && type->AsTableType()->IsUnspecifiedTable() ) - // Ok. - break; - - auto e = check_and_promote_expr(a->GetExpr(), type); + auto e = check_and_promote_expr(a->GetExpr(), ytype); if ( e ) { @@ -377,120 +415,79 @@ void Attributes::CheckAttr(Attr* a) break; } - a->GetExpr()->Error("&default value has inconsistent type", type.get()); - return; + Error("&default value has inconsistent type 2"); } - TableType* tt = type->AsTableType(); - const auto& ytype = tt->Yield(); + // Ok. + break; + } - if ( ! in_record ) - { - // &default applies to the type itself. - if ( ! same_type(atype, ytype) ) - { - // It can still be a default function. - if ( atype->Tag() == TYPE_FUNC ) - { - FuncType* f = atype->AsFuncType(); - if ( ! f->CheckArgs(tt->GetIndexTypes()) || - ! same_type(f->Yield(), ytype) ) - Error("&default function type clash"); - - // Ok. - break; - } - - // Table defaults may be promotable. - if ( (ytype->Tag() == TYPE_RECORD && atype->Tag() == TYPE_RECORD && - record_promotion_compatible(atype->AsRecordType(), - ytype->AsRecordType())) ) - // Ok. - break; - - auto e = check_and_promote_expr(a->GetExpr(), ytype); - - if ( e ) - { - a->SetAttrExpr(std::move(e)); - // Ok. - break; - } - - Error("&default value has inconsistent type 2"); - } + else + { + // &default applies to record field. + if ( same_type(atype, type) ) // Ok. break; - } - else + if ( (atype->Tag() == TYPE_TABLE && atype->AsTableType()->IsUnspecifiedTable()) ) { - // &default applies to record field. + auto e = check_and_promote_expr(a->GetExpr(), type); - if ( same_type(atype, type) ) - // Ok. - break; - - if ( (atype->Tag() == TYPE_TABLE && - atype->AsTableType()->IsUnspecifiedTable()) ) + if ( e ) { - auto e = check_and_promote_expr(a->GetExpr(), type); - - if ( e ) - { - a->SetAttrExpr(std::move(e)); - break; - } - } - - // Table defaults may be promotable. - if ( ytype && ytype->Tag() == TYPE_RECORD && atype->Tag() == TYPE_RECORD && - record_promotion_compatible(atype->AsRecordType(), ytype->AsRecordType()) ) - // Ok. + a->SetAttrExpr(std::move(e)); break; - - Error("&default value has inconsistent type"); + } } + + // Table defaults may be promotable. + if ( ytype && ytype->Tag() == TYPE_RECORD && atype->Tag() == TYPE_RECORD && + record_promotion_compatible(atype->AsRecordType(), ytype->AsRecordType()) ) + // Ok. + break; + + Error("&default value has inconsistent type"); } + } break; case ATTR_EXPIRE_READ: - { - if ( Find(ATTR_BROKER_STORE) ) - Error("&broker_store and &read_expire cannot be used simultaneously"); + { + if ( Find(ATTR_BROKER_STORE) ) + Error("&broker_store and &read_expire cannot be used simultaneously"); - if ( Find(ATTR_BACKEND) ) - Error("&backend and &read_expire cannot be used simultaneously"); - } + if ( Find(ATTR_BACKEND) ) + Error("&backend and &read_expire cannot be used simultaneously"); + } // fallthrough case ATTR_EXPIRE_WRITE: case ATTR_EXPIRE_CREATE: + { + if ( type->Tag() != TYPE_TABLE ) { - if ( type->Tag() != TYPE_TABLE ) - { - Error("expiration only applicable to sets/tables"); - break; - } - - int num_expires = 0; - - for ( const auto& a : attrs ) - { - if ( a->Tag() == ATTR_EXPIRE_READ || a->Tag() == ATTR_EXPIRE_WRITE || - a->Tag() == ATTR_EXPIRE_CREATE ) - num_expires++; - } - - if ( num_expires > 1 ) - { - Error("set/table can only have one of &read_expire, &write_expire, " - "&create_expire"); - break; - } + Error("expiration only applicable to sets/tables"); + break; } + int num_expires = 0; + + for ( const auto& a : attrs ) + { + if ( a->Tag() == ATTR_EXPIRE_READ || a->Tag() == ATTR_EXPIRE_WRITE || + a->Tag() == ATTR_EXPIRE_CREATE ) + num_expires++; + } + + if ( num_expires > 1 ) + { + Error("set/table can only have one of &read_expire, &write_expire, " + "&create_expire"); + break; + } + } + #if 0 //### not easy to test this w/o knowing the ID. if ( ! global_var ) @@ -500,172 +497,172 @@ void Attributes::CheckAttr(Attr* a) break; case ATTR_EXPIRE_FUNC: + { + if ( type->Tag() != TYPE_TABLE ) { - if ( type->Tag() != TYPE_TABLE ) - { - Error("expiration only applicable to tables"); - break; - } - - type->AsTableType()->CheckExpireFuncCompatibility({NewRef{}, a}); - - if ( Find(ATTR_BROKER_STORE) ) - Error("&broker_store and &expire_func cannot be used simultaneously"); - - if ( Find(ATTR_BACKEND) ) - Error("&backend and &expire_func cannot be used simultaneously"); - + Error("expiration only applicable to tables"); break; } + type->AsTableType()->CheckExpireFuncCompatibility({NewRef{}, a}); + + if ( Find(ATTR_BROKER_STORE) ) + Error("&broker_store and &expire_func cannot be used simultaneously"); + + if ( Find(ATTR_BACKEND) ) + Error("&backend and &expire_func cannot be used simultaneously"); + + break; + } + case ATTR_ON_CHANGE: + { + if ( type->Tag() != TYPE_TABLE ) { - if ( type->Tag() != TYPE_TABLE ) - { - Error("&on_change only applicable to sets/tables"); - break; - } - - const auto& change_func = a->GetExpr(); - - if ( change_func->GetType()->Tag() != TYPE_FUNC || - change_func->GetType()->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION ) - Error("&on_change attribute is not a function"); - - const FuncType* c_ft = change_func->GetType()->AsFuncType(); - - if ( c_ft->Yield()->Tag() != TYPE_VOID ) - { - Error("&on_change must not return a value"); - break; - } - - const TableType* the_table = type->AsTableType(); - - if ( the_table->IsUnspecifiedTable() ) - break; - - const auto& args = c_ft->ParamList()->GetTypes(); - const auto& t_indexes = the_table->GetIndexTypes(); - if ( args.size() != (type->IsSet() ? 2 : 3) + t_indexes.size() ) - { - Error("&on_change function has incorrect number of arguments"); - break; - } - - if ( ! same_type(args[0], the_table->AsTableType()) ) - { - Error("&on_change: first argument must be of same type as table"); - break; - } - - // can't check exact type here yet - the data structures don't exist yet. - if ( args[1]->Tag() != TYPE_ENUM ) - { - Error("&on_change: second argument must be a TableChange enum"); - break; - } - - for ( size_t i = 0; i < t_indexes.size(); i++ ) - { - if ( ! same_type(args[2 + i], t_indexes[i]) ) - { - Error("&on_change: index types do not match table"); - break; - } - } - - if ( ! type->IsSet() ) - if ( ! same_type(args[2 + t_indexes.size()], the_table->Yield()) ) - { - Error("&on_change: value type does not match table"); - break; - } + Error("&on_change only applicable to sets/tables"); + break; } + + const auto& change_func = a->GetExpr(); + + if ( change_func->GetType()->Tag() != TYPE_FUNC || + change_func->GetType()->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION ) + Error("&on_change attribute is not a function"); + + const FuncType* c_ft = change_func->GetType()->AsFuncType(); + + if ( c_ft->Yield()->Tag() != TYPE_VOID ) + { + Error("&on_change must not return a value"); + break; + } + + const TableType* the_table = type->AsTableType(); + + if ( the_table->IsUnspecifiedTable() ) + break; + + const auto& args = c_ft->ParamList()->GetTypes(); + const auto& t_indexes = the_table->GetIndexTypes(); + if ( args.size() != (type->IsSet() ? 2 : 3) + t_indexes.size() ) + { + Error("&on_change function has incorrect number of arguments"); + break; + } + + if ( ! same_type(args[0], the_table->AsTableType()) ) + { + Error("&on_change: first argument must be of same type as table"); + break; + } + + // can't check exact type here yet - the data structures don't exist yet. + if ( args[1]->Tag() != TYPE_ENUM ) + { + Error("&on_change: second argument must be a TableChange enum"); + break; + } + + for ( size_t i = 0; i < t_indexes.size(); i++ ) + { + if ( ! same_type(args[2 + i], t_indexes[i]) ) + { + Error("&on_change: index types do not match table"); + break; + } + } + + if ( ! type->IsSet() ) + if ( ! same_type(args[2 + t_indexes.size()], the_table->Yield()) ) + { + Error("&on_change: value type does not match table"); + break; + } + } break; case ATTR_BACKEND: + { + if ( ! global_var || type->Tag() != TYPE_TABLE ) { - if ( ! global_var || type->Tag() != TYPE_TABLE ) - { - Error("&backend only applicable to global sets/tables"); - break; - } - - // cannot do better equality check - the Broker types are not - // actually existing yet when we are here. We will do that - // later - before actually attaching to a broker store - if ( a->GetExpr()->GetType()->Tag() != TYPE_ENUM ) - { - Error("&backend must take an enum argument"); - break; - } - - // Only support atomic types for the moment, unless - // explicitly overriden - if ( ! type->AsTableType()->IsSet() && - ! input::Manager::IsCompatibleType(type->AsTableType()->Yield().get(), true) && - ! Find(ATTR_BROKER_STORE_ALLOW_COMPLEX) ) - { - Error("&backend only supports atomic types as table value"); - } - - if ( Find(ATTR_EXPIRE_FUNC) ) - Error("&backend and &expire_func cannot be used simultaneously"); - - if ( Find(ATTR_EXPIRE_READ) ) - Error("&backend and &read_expire cannot be used simultaneously"); - - if ( Find(ATTR_BROKER_STORE) ) - Error("&backend and &broker_store cannot be used simultaneously"); - + Error("&backend only applicable to global sets/tables"); break; } + // cannot do better equality check - the Broker types are not + // actually existing yet when we are here. We will do that + // later - before actually attaching to a broker store + if ( a->GetExpr()->GetType()->Tag() != TYPE_ENUM ) + { + Error("&backend must take an enum argument"); + break; + } + + // Only support atomic types for the moment, unless + // explicitly overriden + if ( ! type->AsTableType()->IsSet() && + ! input::Manager::IsCompatibleType(type->AsTableType()->Yield().get(), true) && + ! Find(ATTR_BROKER_STORE_ALLOW_COMPLEX) ) + { + Error("&backend only supports atomic types as table value"); + } + + if ( Find(ATTR_EXPIRE_FUNC) ) + Error("&backend and &expire_func cannot be used simultaneously"); + + if ( Find(ATTR_EXPIRE_READ) ) + Error("&backend and &read_expire cannot be used simultaneously"); + + if ( Find(ATTR_BROKER_STORE) ) + Error("&backend and &broker_store cannot be used simultaneously"); + + break; + } + case ATTR_BROKER_STORE: + { + if ( type->Tag() != TYPE_TABLE ) { - if ( type->Tag() != TYPE_TABLE ) - { - Error("&broker_store only applicable to sets/tables"); - break; - } - - if ( a->GetExpr()->GetType()->Tag() != TYPE_STRING ) - { - Error("&broker_store must take a string argument"); - break; - } - - // Only support atomic types for the moment, unless - // explicitly overriden - if ( ! type->AsTableType()->IsSet() && - ! input::Manager::IsCompatibleType(type->AsTableType()->Yield().get(), true) && - ! Find(ATTR_BROKER_STORE_ALLOW_COMPLEX) ) - { - Error("&broker_store only supports atomic types as table value"); - } - - if ( Find(ATTR_EXPIRE_FUNC) ) - Error("&broker_store and &expire_func cannot be used simultaneously"); - - if ( Find(ATTR_EXPIRE_READ) ) - Error("&broker_store and &read_expire cannot be used simultaneously"); - - if ( Find(ATTR_BACKEND) ) - Error("&backend and &broker_store cannot be used simultaneously"); - + Error("&broker_store only applicable to sets/tables"); break; } - case ATTR_BROKER_STORE_ALLOW_COMPLEX: + if ( a->GetExpr()->GetType()->Tag() != TYPE_STRING ) { - if ( type->Tag() != TYPE_TABLE ) - { - Error("&broker_allow_complex_type only applicable to sets/tables"); - break; - } + Error("&broker_store must take a string argument"); + break; } + // Only support atomic types for the moment, unless + // explicitly overriden + if ( ! type->AsTableType()->IsSet() && + ! input::Manager::IsCompatibleType(type->AsTableType()->Yield().get(), true) && + ! Find(ATTR_BROKER_STORE_ALLOW_COMPLEX) ) + { + Error("&broker_store only supports atomic types as table value"); + } + + if ( Find(ATTR_EXPIRE_FUNC) ) + Error("&broker_store and &expire_func cannot be used simultaneously"); + + if ( Find(ATTR_EXPIRE_READ) ) + Error("&broker_store and &read_expire cannot be used simultaneously"); + + if ( Find(ATTR_BACKEND) ) + Error("&backend and &broker_store cannot be used simultaneously"); + + break; + } + + case ATTR_BROKER_STORE_ALLOW_COMPLEX: + { + if ( type->Tag() != TYPE_TABLE ) + { + Error("&broker_allow_complex_type only applicable to sets/tables"); + break; + } + } + case ATTR_TRACKED: // FIXME: Check here for global ID? break; @@ -695,24 +692,24 @@ void Attributes::CheckAttr(Attr* a) break; case ATTR_TYPE_COLUMN: + { + if ( type->Tag() != TYPE_PORT ) { - if ( type->Tag() != TYPE_PORT ) - { - Error("type_column tag only applicable to ports"); - break; - } - - const auto& atype = a->GetExpr()->GetType(); - - if ( atype->Tag() != TYPE_STRING ) - { - Error("type column needs to have a string argument"); - break; - } - + Error("type_column tag only applicable to ports"); break; } + const auto& atype = a->GetExpr()->GetType(); + + if ( atype->Tag() != TYPE_STRING ) + { + Error("type column needs to have a string argument"); + break; + } + + break; + } + default: BadTag("Attributes::CheckAttr", attr_name(a->Tag())); } diff --git a/src/CompHash.cc b/src/CompHash.cc index 72fe39364f..89b5201238 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -158,326 +158,319 @@ bool CompositeHash::RecoverOneVal(const HashKey& hk, Type* t, ValPtr* pval, bool switch ( it ) { case TYPE_INTERNAL_INT: - { - bro_int_t i; - hk.Read("int", i); + { + bro_int_t i; + hk.Read("int", i); - if ( tag == TYPE_ENUM ) - *pval = t->AsEnumType()->GetEnumVal(i); - else if ( tag == TYPE_BOOL ) - *pval = val_mgr->Bool(i); - else if ( tag == TYPE_INT ) - *pval = val_mgr->Int(i); - else - { + if ( tag == TYPE_ENUM ) + *pval = t->AsEnumType()->GetEnumVal(i); + else if ( tag == TYPE_BOOL ) + *pval = val_mgr->Bool(i); + else if ( tag == TYPE_INT ) + *pval = val_mgr->Int(i); + else + { + reporter->InternalError( + "bad internal unsigned int in CompositeHash::RecoverOneVal()"); + *pval = nullptr; + return false; + } + } + break; + + case TYPE_INTERNAL_UNSIGNED: + { + bro_uint_t u; + hk.Read("unsigned", u); + + switch ( tag ) + { + case TYPE_COUNT: + *pval = val_mgr->Count(u); + break; + + case TYPE_PORT: + *pval = val_mgr->Port(u); + break; + + default: reporter->InternalError( "bad internal unsigned int in CompositeHash::RecoverOneVal()"); *pval = nullptr; return false; - } - } - break; - - case TYPE_INTERNAL_UNSIGNED: - { - bro_uint_t u; - hk.Read("unsigned", u); - - switch ( tag ) - { - case TYPE_COUNT: - *pval = val_mgr->Count(u); - break; - - case TYPE_PORT: - *pval = val_mgr->Port(u); - break; - - default: - reporter->InternalError( - "bad internal unsigned int in CompositeHash::RecoverOneVal()"); - *pval = nullptr; - return false; - } } + } break; case TYPE_INTERNAL_DOUBLE: - { - double d; - hk.Read("double", d); + { + double d; + hk.Read("double", d); - if ( tag == TYPE_INTERVAL ) - *pval = make_intrusive(d, 1.0); - else if ( tag == TYPE_TIME ) - *pval = make_intrusive(d); - else - *pval = make_intrusive(d); - } + if ( tag == TYPE_INTERVAL ) + *pval = make_intrusive(d, 1.0); + else if ( tag == TYPE_TIME ) + *pval = make_intrusive(d); + else + *pval = make_intrusive(d); + } break; case TYPE_INTERNAL_ADDR: + { + hk.AlignRead(sizeof(uint32_t)); + hk.EnsureReadSpace(sizeof(uint32_t) * 4); + IPAddr addr(IPv6, static_cast(hk.KeyAtRead()), IPAddr::Network); + hk.SkipRead("addr", sizeof(uint32_t) * 4); + + switch ( tag ) { - hk.AlignRead(sizeof(uint32_t)); - hk.EnsureReadSpace(sizeof(uint32_t) * 4); - IPAddr addr(IPv6, static_cast(hk.KeyAtRead()), IPAddr::Network); - hk.SkipRead("addr", sizeof(uint32_t) * 4); + case TYPE_ADDR: + *pval = make_intrusive(addr); + break; - switch ( tag ) - { - case TYPE_ADDR: - *pval = make_intrusive(addr); - break; - - default: - reporter->InternalError( - "bad internal address in CompositeHash::RecoverOneVal()"); - *pval = nullptr; - return false; - } + default: + reporter->InternalError( + "bad internal address in CompositeHash::RecoverOneVal()"); + *pval = nullptr; + return false; } + } break; case TYPE_INTERNAL_SUBNET: - { - hk.AlignRead(sizeof(uint32_t)); - hk.EnsureReadSpace(sizeof(uint32_t) * 4); - IPAddr addr(IPv6, static_cast(hk.KeyAtRead()), IPAddr::Network); - hk.SkipRead("subnet", sizeof(uint32_t) * 4); + { + hk.AlignRead(sizeof(uint32_t)); + hk.EnsureReadSpace(sizeof(uint32_t) * 4); + IPAddr addr(IPv6, static_cast(hk.KeyAtRead()), IPAddr::Network); + hk.SkipRead("subnet", sizeof(uint32_t) * 4); - uint32_t width; - hk.Read("subnet-width", width); - *pval = make_intrusive(addr, width); - } + uint32_t width; + hk.Read("subnet-width", width); + *pval = make_intrusive(addr, width); + } break; case TYPE_INTERNAL_VOID: case TYPE_INTERNAL_OTHER: + { + switch ( t->Tag() ) { - switch ( t->Tag() ) + case TYPE_FUNC: { - case TYPE_FUNC: + uint32_t id; + hk.Read("func", id); + const auto& f = Func::GetFuncPtrByID(id); + + if ( ! f ) + reporter->InternalError("failed to look up unique function id %" PRIu32 + " in CompositeHash::RecoverOneVal()", + id); + + *pval = make_intrusive(f); + const auto& pvt = (*pval)->GetType(); + + if ( ! pvt ) + reporter->InternalError( + "bad aggregate Val in CompositeHash::RecoverOneVal()"); + + else if ( t->Tag() != TYPE_FUNC && ! same_type(pvt, t) ) + // ### Maybe fix later, but may be fundamentally un-checkable --US + { + reporter->InternalError( + "inconsistent aggregate Val in CompositeHash::RecoverOneVal()"); + *pval = nullptr; + return false; + } + + // ### A crude approximation for now. + else if ( t->Tag() == TYPE_FUNC && pvt->Tag() != TYPE_FUNC ) + { + reporter->InternalError( + "inconsistent aggregate Val in CompositeHash::RecoverOneVal()"); + *pval = nullptr; + return false; + } + } + break; + + case TYPE_PATTERN: + { + const char* texts[2] = {nullptr, nullptr}; + uint64_t lens[2] = {0, 0}; + + if ( ! singleton ) + { + hk.Read("pattern-len1", lens[0]); + hk.Read("pattern-len2", lens[1]); + } + + texts[0] = static_cast(hk.KeyAtRead()); + hk.SkipRead("pattern-string1", strlen(texts[0]) + 1); + texts[1] = static_cast(hk.KeyAtRead()); + hk.SkipRead("pattern-string2", strlen(texts[1]) + 1); + + RE_Matcher* re = new RE_Matcher(texts[0], texts[1]); + + if ( ! re->Compile() ) + reporter->InternalError("failed compiling table/set key pattern: %s", + re->PatternText()); + + *pval = make_intrusive(re); + } + break; + + case TYPE_RECORD: + { + auto rt = t->AsRecordType(); + int num_fields = rt->NumFields(); + + std::vector values; + int i; + for ( i = 0; i < num_fields; ++i ) + { + ValPtr v; + Attributes* a = rt->FieldDecl(i)->attrs.get(); + bool optional = (a && a->Find(ATTR_OPTIONAL)); + + if ( ! RecoverOneVal(hk, rt->GetFieldType(i).get(), &v, optional, false) ) { - uint32_t id; - hk.Read("func", id); - const auto& f = Func::GetFuncPtrByID(id); - - if ( ! f ) - reporter->InternalError( - "failed to look up unique function id %" PRIu32 - " in CompositeHash::RecoverOneVal()", - id); - - *pval = make_intrusive(f); - const auto& pvt = (*pval)->GetType(); - - if ( ! pvt ) - reporter->InternalError( - "bad aggregate Val in CompositeHash::RecoverOneVal()"); - - else if ( t->Tag() != TYPE_FUNC && ! same_type(pvt, t) ) - // ### Maybe fix later, but may be fundamentally un-checkable --US - { - reporter->InternalError( - "inconsistent aggregate Val in CompositeHash::RecoverOneVal()"); - *pval = nullptr; - return false; - } - - // ### A crude approximation for now. - else if ( t->Tag() == TYPE_FUNC && pvt->Tag() != TYPE_FUNC ) - { - reporter->InternalError( - "inconsistent aggregate Val in CompositeHash::RecoverOneVal()"); - *pval = nullptr; - return false; - } - } - break; - - case TYPE_PATTERN: - { - const char* texts[2] = {nullptr, nullptr}; - uint64_t lens[2] = {0, 0}; - - if ( ! singleton ) - { - hk.Read("pattern-len1", lens[0]); - hk.Read("pattern-len2", lens[1]); - } - - texts[0] = static_cast(hk.KeyAtRead()); - hk.SkipRead("pattern-string1", strlen(texts[0]) + 1); - texts[1] = static_cast(hk.KeyAtRead()); - hk.SkipRead("pattern-string2", strlen(texts[1]) + 1); - - RE_Matcher* re = new RE_Matcher(texts[0], texts[1]); - - if ( ! re->Compile() ) - reporter->InternalError( - "failed compiling table/set key pattern: %s", - re->PatternText()); - - *pval = make_intrusive(re); - } - break; - - case TYPE_RECORD: - { - auto rt = t->AsRecordType(); - int num_fields = rt->NumFields(); - - std::vector values; - int i; - for ( i = 0; i < num_fields; ++i ) - { - ValPtr v; - Attributes* a = rt->FieldDecl(i)->attrs.get(); - bool optional = (a && a->Find(ATTR_OPTIONAL)); - - if ( ! RecoverOneVal(hk, rt->GetFieldType(i).get(), &v, optional, - false) ) - { - *pval = nullptr; - return false; - } - - // An earlier call to reporter->InternalError would have called - // abort() and broken the call tree that clang-tidy is relying on to - // get the error described. - // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.Branch) - if ( ! (v || optional) ) - { - reporter->InternalError( - "didn't recover expected number of fields from HashKey"); - *pval = nullptr; - return false; - } - - values.emplace_back(std::move(v)); - } - - ASSERT(int(values.size()) == num_fields); - - auto rv = make_intrusive(IntrusivePtr{NewRef{}, rt}); - - for ( int i = 0; i < num_fields; ++i ) - rv->Assign(i, std::move(values[i])); - - *pval = std::move(rv); - } - break; - - case TYPE_TABLE: - { - int n; - hk.Read("table-size", n); - auto tt = t->AsTableType(); - auto tv = make_intrusive(IntrusivePtr{NewRef{}, tt}); - - for ( int i = 0; i < n; ++i ) - { - ValPtr key; - if ( ! RecoverOneVal(hk, tt->GetIndices().get(), &key, false, - false) ) - { - *pval = nullptr; - return false; - } - - if ( t->IsSet() ) - tv->Assign(std::move(key), nullptr); - else - { - ValPtr value; - if ( ! RecoverOneVal(hk, tt->Yield().get(), &value, false, - false) ) - { - *pval = nullptr; - return false; - } - tv->Assign(std::move(key), std::move(value)); - } - } - - *pval = std::move(tv); - } - break; - - case TYPE_VECTOR: - { - unsigned int n; - hk.Read("vector-size", n); - auto vt = t->AsVectorType(); - auto vv = make_intrusive(IntrusivePtr{NewRef{}, vt}); - - for ( unsigned int i = 0; i < n; ++i ) - { - unsigned int index; - hk.Read("vector-idx", index); - bool have_val; - hk.Read("vector-idx-present", have_val); - ValPtr value; - - if ( have_val && - ! RecoverOneVal(hk, vt->Yield().get(), &value, false, false) ) - { - *pval = nullptr; - return false; - } - - vv->Assign(index, std::move(value)); - } - - *pval = std::move(vv); - } - break; - - case TYPE_LIST: - { - int n; - hk.Read("list-size", n); - auto tl = t->AsTypeList(); - auto lv = make_intrusive(TYPE_ANY); - - for ( int i = 0; i < n; ++i ) - { - ValPtr v; - Type* it = tl->GetTypes()[i].get(); - if ( ! RecoverOneVal(hk, it, &v, false, false) ) - return false; - lv->Append(std::move(v)); - } - - *pval = std::move(lv); - } - break; - - default: - { - reporter->InternalError( - "bad index type in CompositeHash::RecoverOneVal"); *pval = nullptr; return false; } + + // An earlier call to reporter->InternalError would have called + // abort() and broken the call tree that clang-tidy is relying on to + // get the error described. + // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.Branch) + if ( ! (v || optional) ) + { + reporter->InternalError( + "didn't recover expected number of fields from HashKey"); + *pval = nullptr; + return false; + } + + values.emplace_back(std::move(v)); + } + + ASSERT(int(values.size()) == num_fields); + + auto rv = make_intrusive(IntrusivePtr{NewRef{}, rt}); + + for ( int i = 0; i < num_fields; ++i ) + rv->Assign(i, std::move(values[i])); + + *pval = std::move(rv); + } + break; + + case TYPE_TABLE: + { + int n; + hk.Read("table-size", n); + auto tt = t->AsTableType(); + auto tv = make_intrusive(IntrusivePtr{NewRef{}, tt}); + + for ( int i = 0; i < n; ++i ) + { + ValPtr key; + if ( ! RecoverOneVal(hk, tt->GetIndices().get(), &key, false, false) ) + { + *pval = nullptr; + return false; + } + + if ( t->IsSet() ) + tv->Assign(std::move(key), nullptr); + else + { + ValPtr value; + if ( ! RecoverOneVal(hk, tt->Yield().get(), &value, false, false) ) + { + *pval = nullptr; + return false; + } + tv->Assign(std::move(key), std::move(value)); + } + } + + *pval = std::move(tv); + } + break; + + case TYPE_VECTOR: + { + unsigned int n; + hk.Read("vector-size", n); + auto vt = t->AsVectorType(); + auto vv = make_intrusive(IntrusivePtr{NewRef{}, vt}); + + for ( unsigned int i = 0; i < n; ++i ) + { + unsigned int index; + hk.Read("vector-idx", index); + bool have_val; + hk.Read("vector-idx-present", have_val); + ValPtr value; + + if ( have_val && + ! RecoverOneVal(hk, vt->Yield().get(), &value, false, false) ) + { + *pval = nullptr; + return false; + } + + vv->Assign(index, std::move(value)); + } + + *pval = std::move(vv); + } + break; + + case TYPE_LIST: + { + int n; + hk.Read("list-size", n); + auto tl = t->AsTypeList(); + auto lv = make_intrusive(TYPE_ANY); + + for ( int i = 0; i < n; ++i ) + { + ValPtr v; + Type* it = tl->GetTypes()[i].get(); + if ( ! RecoverOneVal(hk, it, &v, false, false) ) + return false; + lv->Append(std::move(v)); + } + + *pval = std::move(lv); + } + break; + + default: + { + reporter->InternalError("bad index type in CompositeHash::RecoverOneVal"); + *pval = nullptr; + return false; } } + } break; case TYPE_INTERNAL_STRING: + { + int n = hk.Size(); + + if ( ! singleton ) { - int n = hk.Size(); - - if ( ! singleton ) - { - hk.Read("string-len", n); - hk.EnsureReadSpace(n); - } - - *pval = - make_intrusive(new String((const byte_vec)hk.KeyAtRead(), n, true)); - hk.SkipRead("string", n); + hk.Read("string-len", n); + hk.EnsureReadSpace(n); } + + *pval = make_intrusive(new String((const byte_vec)hk.KeyAtRead(), n, true)); + hk.SkipRead("string", n); + } break; case TYPE_INTERNAL_ERROR: @@ -545,164 +538,161 @@ bool CompositeHash::SingleValHash(HashKey& hk, const Val* v, Type* bt, bool type case TYPE_INTERNAL_VOID: case TYPE_INTERNAL_OTHER: + { + switch ( v->GetType()->Tag() ) { - switch ( v->GetType()->Tag() ) + case TYPE_FUNC: + hk.Write("func", v->AsFunc()->GetUniqueFuncID()); + break; + + case TYPE_PATTERN: { - case TYPE_FUNC: - hk.Write("func", v->AsFunc()->GetUniqueFuncID()); - break; + const char* texts[2] = {v->AsPattern()->PatternText(), + v->AsPattern()->AnywherePatternText()}; + uint64_t lens[2] = {strlen(texts[0]) + 1, strlen(texts[1]) + 1}; - case TYPE_PATTERN: - { - const char* texts[2] = {v->AsPattern()->PatternText(), - v->AsPattern()->AnywherePatternText()}; - uint64_t lens[2] = {strlen(texts[0]) + 1, strlen(texts[1]) + 1}; + if ( ! singleton ) + { + hk.Write("pattern-len1", lens[0]); + hk.Write("pattern-len2", lens[1]); + } + else + { + hk.Reserve("pattern", lens[0] + lens[1]); + hk.Allocate(); + } - if ( ! singleton ) - { - hk.Write("pattern-len1", lens[0]); - hk.Write("pattern-len2", lens[1]); - } - else - { - hk.Reserve("pattern", lens[0] + lens[1]); - hk.Allocate(); - } - - hk.Write("pattern-string1", static_cast(texts[0]), - lens[0]); - hk.Write("pattern-string2", static_cast(texts[1]), - lens[1]); - break; - } - - case TYPE_RECORD: - { - auto rv = v->AsRecordVal(); - auto rt = bt->AsRecordType(); - int num_fields = rt->NumFields(); - - if ( ! EnsureTypeReserve(hk, v, bt, type_check) ) - return false; - - for ( int i = 0; i < num_fields; ++i ) - { - auto rv_i = rv->GetField(i); - - Attributes* a = rt->FieldDecl(i)->attrs.get(); - bool optional_attr = (a && a->Find(ATTR_OPTIONAL)); - - if ( ! (rv_i || optional_attr) ) - return false; - - if ( ! SingleValHash(hk, rv_i.get(), rt->GetFieldType(i).get(), - type_check, optional_attr, false) ) - return false; - } - break; - } - - case TYPE_TABLE: - { - if ( ! EnsureTypeReserve(hk, v, bt, type_check) ) - return false; - - auto tv = v->AsTableVal(); - auto hashkeys = ordered_hashkeys(tv); - - hk.Write("table-size", tv->Size()); - - for ( auto& kv : *hashkeys ) - { - auto key = kv.second; - - if ( ! SingleValHash(hk, key.get(), key->GetType().get(), - type_check, false, false) ) - return false; - - if ( ! v->GetType()->IsSet() ) - { - auto val = const_cast(tv)->FindOrDefault(key); - - if ( ! SingleValHash(hk, val.get(), val->GetType().get(), - type_check, false, false) ) - return false; - } - } - } - break; - - case TYPE_VECTOR: - { - if ( ! EnsureTypeReserve(hk, v, bt, type_check) ) - return false; - - auto vv = v->AsVectorVal(); - auto vt = v->GetType()->AsVectorType(); - - hk.Write("vector-size", vv->Size()); - - for ( unsigned int i = 0; i < vv->Size(); ++i ) - { - auto val = vv->ValAt(i); - hk.Write("vector-idx", i); - hk.Write("vector-idx-present", val != nullptr); - - if ( val && ! SingleValHash(hk, val.get(), vt->Yield().get(), - type_check, false, false) ) - return false; - } - } - break; - - case TYPE_LIST: - { - if ( ! hk.IsAllocated() ) - { - if ( ! ReserveSingleTypeKeySize(hk, bt, v, type_check, false, false, - false) ) - return false; - - hk.Allocate(); - } - - auto lv = v->AsListVal(); - - hk.Write("list-size", lv->Length()); - - for ( int i = 0; i < lv->Length(); ++i ) - { - Val* entry_val = lv->Idx(i).get(); - if ( ! SingleValHash(hk, entry_val, entry_val->GetType().get(), - type_check, false, false) ) - return false; - } - } - break; - - default: - { - reporter->InternalError( - "bad index type in CompositeHash::SingleValHash"); - return false; - } + hk.Write("pattern-string1", static_cast(texts[0]), lens[0]); + hk.Write("pattern-string2", static_cast(texts[1]), lens[1]); + break; } - break; // case TYPE_INTERNAL_VOID/OTHER + case TYPE_RECORD: + { + auto rv = v->AsRecordVal(); + auto rt = bt->AsRecordType(); + int num_fields = rt->NumFields(); + + if ( ! EnsureTypeReserve(hk, v, bt, type_check) ) + return false; + + for ( int i = 0; i < num_fields; ++i ) + { + auto rv_i = rv->GetField(i); + + Attributes* a = rt->FieldDecl(i)->attrs.get(); + bool optional_attr = (a && a->Find(ATTR_OPTIONAL)); + + if ( ! (rv_i || optional_attr) ) + return false; + + if ( ! SingleValHash(hk, rv_i.get(), rt->GetFieldType(i).get(), type_check, + optional_attr, false) ) + return false; + } + break; + } + + case TYPE_TABLE: + { + if ( ! EnsureTypeReserve(hk, v, bt, type_check) ) + return false; + + auto tv = v->AsTableVal(); + auto hashkeys = ordered_hashkeys(tv); + + hk.Write("table-size", tv->Size()); + + for ( auto& kv : *hashkeys ) + { + auto key = kv.second; + + if ( ! SingleValHash(hk, key.get(), key->GetType().get(), type_check, false, + false) ) + return false; + + if ( ! v->GetType()->IsSet() ) + { + auto val = const_cast(tv)->FindOrDefault(key); + + if ( ! SingleValHash(hk, val.get(), val->GetType().get(), type_check, + false, false) ) + return false; + } + } + } + break; + + case TYPE_VECTOR: + { + if ( ! EnsureTypeReserve(hk, v, bt, type_check) ) + return false; + + auto vv = v->AsVectorVal(); + auto vt = v->GetType()->AsVectorType(); + + hk.Write("vector-size", vv->Size()); + + for ( unsigned int i = 0; i < vv->Size(); ++i ) + { + auto val = vv->ValAt(i); + hk.Write("vector-idx", i); + hk.Write("vector-idx-present", val != nullptr); + + if ( val && ! SingleValHash(hk, val.get(), vt->Yield().get(), type_check, + false, false) ) + return false; + } + } + break; + + case TYPE_LIST: + { + if ( ! hk.IsAllocated() ) + { + if ( ! ReserveSingleTypeKeySize(hk, bt, v, type_check, false, false, + false) ) + return false; + + hk.Allocate(); + } + + auto lv = v->AsListVal(); + + hk.Write("list-size", lv->Length()); + + for ( int i = 0; i < lv->Length(); ++i ) + { + Val* entry_val = lv->Idx(i).get(); + if ( ! SingleValHash(hk, entry_val, entry_val->GetType().get(), type_check, + false, false) ) + return false; + } + } + break; + + default: + { + reporter->InternalError("bad index type in CompositeHash::SingleValHash"); + return false; + } } + break; // case TYPE_INTERNAL_VOID/OTHER + } + case TYPE_INTERNAL_STRING: - { - if ( ! EnsureTypeReserve(hk, v, bt, type_check) ) - return false; + { + if ( ! EnsureTypeReserve(hk, v, bt, type_check) ) + return false; - const auto sval = v->AsString(); + const auto sval = v->AsString(); - if ( ! singleton ) - hk.Write("string-len", sval->Len()); + if ( ! singleton ) + hk.Write("string-len", sval->Len()); - hk.Write("string", sval->Bytes(), sval->Len()); - } + hk.Write("string", sval->Bytes(), sval->Len()); + } break; case TYPE_INTERNAL_ERROR: @@ -783,138 +773,137 @@ bool CompositeHash::ReserveSingleTypeKeySize(HashKey& hk, Type* bt, const Val* v case TYPE_INTERNAL_VOID: case TYPE_INTERNAL_OTHER: + { + switch ( bt->Tag() ) { - switch ( bt->Tag() ) + case TYPE_FUNC: { - case TYPE_FUNC: - { - hk.ReserveType("func"); - break; - } - - case TYPE_PATTERN: - { - if ( ! v ) - return (optional && ! calc_static_size); - - if ( ! singleton ) - { - hk.ReserveType("pattern-len1"); - hk.ReserveType("pattern-len2"); - } - - // +1 in the following to include null terminators - hk.Reserve("pattern-string1", strlen(v->AsPattern()->PatternText()) + 1, - 0); - hk.Reserve("pattern-string1", - strlen(v->AsPattern()->AnywherePatternText()) + 1, 0); - break; - } - - case TYPE_RECORD: - { - if ( ! v ) - return (optional && ! calc_static_size); - - const RecordVal* rv = v->AsRecordVal(); - RecordType* rt = bt->AsRecordType(); - int num_fields = rt->NumFields(); - - for ( int i = 0; i < num_fields; ++i ) - { - Attributes* a = rt->FieldDecl(i)->attrs.get(); - bool optional_attr = (a && a->Find(ATTR_OPTIONAL)); - - auto rv_v = rv ? rv->GetField(i) : nullptr; - if ( ! ReserveSingleTypeKeySize( - hk, rt->GetFieldType(i).get(), rv_v.get(), type_check, - optional_attr, calc_static_size, false) ) - return false; - } - break; - } - - case TYPE_TABLE: - { - if ( ! v ) - return (optional && ! calc_static_size); - - auto tv = v->AsTableVal(); - auto hashkeys = ordered_hashkeys(tv); - - hk.ReserveType("table-size"); - - for ( auto& kv : *hashkeys ) - { - auto key = kv.second; - - if ( ! ReserveSingleTypeKeySize(hk, key->GetType().get(), key.get(), - type_check, false, calc_static_size, - false) ) - return false; - - if ( ! bt->IsSet() ) - { - auto val = const_cast(tv)->FindOrDefault(key); - if ( ! ReserveSingleTypeKeySize(hk, val->GetType().get(), - val.get(), type_check, false, - calc_static_size, false) ) - return false; - } - } - - break; - } - - case TYPE_VECTOR: - { - if ( ! v ) - return (optional && ! calc_static_size); - - hk.ReserveType("vector-size"); - VectorVal* vv = const_cast(v->AsVectorVal()); - for ( unsigned int i = 0; i < vv->Size(); ++i ) - { - auto val = vv->ValAt(i); - hk.ReserveType("vector-idx"); - hk.ReserveType("vector-idx-present"); - if ( val && ! ReserveSingleTypeKeySize( - hk, bt->AsVectorType()->Yield().get(), val.get(), - type_check, false, calc_static_size, false) ) - return false; - } - break; - } - - case TYPE_LIST: - { - if ( ! v ) - return (optional && ! calc_static_size); - - hk.ReserveType("list-size"); - ListVal* lv = const_cast(v->AsListVal()); - for ( int i = 0; i < lv->Length(); ++i ) - { - if ( ! ReserveSingleTypeKeySize(hk, lv->Idx(i)->GetType().get(), - lv->Idx(i).get(), type_check, false, - calc_static_size, false) ) - return false; - } - - break; - } - - default: - { - reporter->InternalError( - "bad index type in CompositeHash::ReserveSingleTypeKeySize"); - return 0; - } + hk.ReserveType("func"); + break; } - break; // case TYPE_INTERNAL_VOID/OTHER + case TYPE_PATTERN: + { + if ( ! v ) + return (optional && ! calc_static_size); + + if ( ! singleton ) + { + hk.ReserveType("pattern-len1"); + hk.ReserveType("pattern-len2"); + } + + // +1 in the following to include null terminators + hk.Reserve("pattern-string1", strlen(v->AsPattern()->PatternText()) + 1, 0); + hk.Reserve("pattern-string1", strlen(v->AsPattern()->AnywherePatternText()) + 1, + 0); + break; + } + + case TYPE_RECORD: + { + if ( ! v ) + return (optional && ! calc_static_size); + + const RecordVal* rv = v->AsRecordVal(); + RecordType* rt = bt->AsRecordType(); + int num_fields = rt->NumFields(); + + for ( int i = 0; i < num_fields; ++i ) + { + Attributes* a = rt->FieldDecl(i)->attrs.get(); + bool optional_attr = (a && a->Find(ATTR_OPTIONAL)); + + auto rv_v = rv ? rv->GetField(i) : nullptr; + if ( ! ReserveSingleTypeKeySize(hk, rt->GetFieldType(i).get(), rv_v.get(), + type_check, optional_attr, calc_static_size, + false) ) + return false; + } + break; + } + + case TYPE_TABLE: + { + if ( ! v ) + return (optional && ! calc_static_size); + + auto tv = v->AsTableVal(); + auto hashkeys = ordered_hashkeys(tv); + + hk.ReserveType("table-size"); + + for ( auto& kv : *hashkeys ) + { + auto key = kv.second; + + if ( ! ReserveSingleTypeKeySize(hk, key->GetType().get(), key.get(), + type_check, false, calc_static_size, + false) ) + return false; + + if ( ! bt->IsSet() ) + { + auto val = const_cast(tv)->FindOrDefault(key); + if ( ! ReserveSingleTypeKeySize(hk, val->GetType().get(), val.get(), + type_check, false, calc_static_size, + false) ) + return false; + } + } + + break; + } + + case TYPE_VECTOR: + { + if ( ! v ) + return (optional && ! calc_static_size); + + hk.ReserveType("vector-size"); + VectorVal* vv = const_cast(v->AsVectorVal()); + for ( unsigned int i = 0; i < vv->Size(); ++i ) + { + auto val = vv->ValAt(i); + hk.ReserveType("vector-idx"); + hk.ReserveType("vector-idx-present"); + if ( val && ! ReserveSingleTypeKeySize( + hk, bt->AsVectorType()->Yield().get(), val.get(), + type_check, false, calc_static_size, false) ) + return false; + } + break; + } + + case TYPE_LIST: + { + if ( ! v ) + return (optional && ! calc_static_size); + + hk.ReserveType("list-size"); + ListVal* lv = const_cast(v->AsListVal()); + for ( int i = 0; i < lv->Length(); ++i ) + { + if ( ! ReserveSingleTypeKeySize(hk, lv->Idx(i)->GetType().get(), + lv->Idx(i).get(), type_check, false, + calc_static_size, false) ) + return false; + } + + break; + } + + default: + { + reporter->InternalError( + "bad index type in CompositeHash::ReserveSingleTypeKeySize"); + return 0; + } } + break; // case TYPE_INTERNAL_VOID/OTHER + } + case TYPE_INTERNAL_STRING: if ( ! v ) return (optional && ! calc_static_size); diff --git a/src/DbgBreakpoint.cc b/src/DbgBreakpoint.cc index b309326b23..01dcbb059a 100644 --- a/src/DbgBreakpoint.cc +++ b/src/DbgBreakpoint.cc @@ -348,19 +348,19 @@ void DbgBreakpoint::PrintHitMsg() case BP_STMT: case BP_FUNC: case BP_LINE: - { - ODesc d; - Frame* f = g_frame_stack.back(); - const ScriptFunc* func = f->GetFunction(); + { + ODesc d; + Frame* f = g_frame_stack.back(); + const ScriptFunc* func = f->GetFunction(); - if ( func ) - func->DescribeDebug(&d, f->GetFuncArgs()); + if ( func ) + func->DescribeDebug(&d, f->GetFuncArgs()); - const Location* loc = at_stmt->GetLocationInfo(); + const Location* loc = at_stmt->GetLocationInfo(); - debug_msg("Breakpoint %d, %s at %s:%d\n", GetID(), d.Description(), loc->filename, - loc->first_line); - } + debug_msg("Breakpoint %d, %s at %s:%d\n", GetID(), d.Description(), loc->filename, + loc->first_line); + } return; case BP_TIME: diff --git a/src/Expr.cc b/src/Expr.cc index 42b6350613..d12c023828 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -320,75 +320,75 @@ const char* assign_to_index(ValPtr v1, ValPtr v2, ValPtr v3, bool& iterators_inv switch ( v1->GetType()->Tag() ) { case TYPE_VECTOR: + { + const ListVal* lv = v2->AsListVal(); + VectorVal* v1_vect = v1->AsVectorVal(); + + if ( lv->Length() > 1 ) { - const ListVal* lv = v2->AsListVal(); - VectorVal* v1_vect = v1->AsVectorVal(); + auto len = v1_vect->Size(); + bro_int_t first = get_slice_index(lv->Idx(0)->CoerceToInt(), len); + bro_int_t last = get_slice_index(lv->Idx(1)->CoerceToInt(), len); - if ( lv->Length() > 1 ) - { - auto len = v1_vect->Size(); - bro_int_t first = get_slice_index(lv->Idx(0)->CoerceToInt(), len); - bro_int_t last = get_slice_index(lv->Idx(1)->CoerceToInt(), len); + // Remove the elements from the vector within the slice. + for ( auto idx = first; idx < last; idx++ ) + v1_vect->Remove(first); - // Remove the elements from the vector within the slice. - for ( auto idx = first; idx < last; idx++ ) - v1_vect->Remove(first); + // Insert the new elements starting at the first + // position. - // Insert the new elements starting at the first - // position. + VectorVal* v_vect = v3->AsVectorVal(); - VectorVal* v_vect = v3->AsVectorVal(); - - for ( auto idx = 0u; idx < v_vect->Size(); idx++, first++ ) - v1_vect->Insert(first, v_vect->ValAt(idx)); - } - - else if ( ! v1_vect->Assign(lv->Idx(0)->CoerceToUnsigned(), std::move(v3)) ) - { - v3 = std::move(v_extra); - - if ( v3 ) - { - ODesc d; - v3->Describe(&d); - const auto& vt = v3->GetType(); - auto vtt = vt->Tag(); - std::string tn = vtt == TYPE_RECORD ? vt->GetName() : type_name(vtt); - return util::fmt( - "vector index assignment failed for invalid type '%s', value: %s", - tn.data(), d.Description()); - } - else - return "assignment failed with null value"; - } - break; + for ( auto idx = 0u; idx < v_vect->Size(); idx++, first++ ) + v1_vect->Insert(first, v_vect->ValAt(idx)); } + else if ( ! v1_vect->Assign(lv->Idx(0)->CoerceToUnsigned(), std::move(v3)) ) + { + v3 = std::move(v_extra); + + if ( v3 ) + { + ODesc d; + v3->Describe(&d); + const auto& vt = v3->GetType(); + auto vtt = vt->Tag(); + std::string tn = vtt == TYPE_RECORD ? vt->GetName() : type_name(vtt); + return util::fmt( + "vector index assignment failed for invalid type '%s', value: %s", + tn.data(), d.Description()); + } + else + return "assignment failed with null value"; + } + break; + } + case TYPE_TABLE: + { + if ( ! v1->AsTableVal()->Assign(std::move(v2), std::move(v3), true, + &iterators_invalidated) ) { - if ( ! v1->AsTableVal()->Assign(std::move(v2), std::move(v3), true, - &iterators_invalidated) ) + v3 = std::move(v_extra); + + if ( v3 ) { - v3 = std::move(v_extra); - - if ( v3 ) - { - ODesc d; - v3->Describe(&d); - const auto& vt = v3->GetType(); - auto vtt = vt->Tag(); - std::string tn = vtt == TYPE_RECORD ? vt->GetName() : type_name(vtt); - return util::fmt( - "table index assignment failed for invalid type '%s', value: %s", - tn.data(), d.Description()); - } - else - return "assignment failed with null value"; + ODesc d; + v3->Describe(&d); + const auto& vt = v3->GetType(); + auto vtt = vt->Tag(); + std::string tn = vtt == TYPE_RECORD ? vt->GetName() : type_name(vtt); + return util::fmt( + "table index assignment failed for invalid type '%s', value: %s", tn.data(), + d.Description()); } - - break; + else + return "assignment failed with null value"; } + break; + } + case TYPE_STRING: return "assignment via string index accessor not allowed"; break; @@ -925,54 +925,54 @@ ValPtr BinaryExpr::Fold(Val* v1, Val* v2) const DO_FOLD(*); break; case EXPR_DIVIDE: + { + if ( is_integral ) { - if ( is_integral ) - { - if ( i2 == 0 ) - RuntimeError("division by zero"); + if ( i2 == 0 ) + RuntimeError("division by zero"); - i3 = i1 / i2; - } - - else if ( is_unsigned ) - { - if ( u2 == 0 ) - RuntimeError("division by zero"); - - u3 = u1 / u2; - } - else - { - if ( d2 == 0 ) - RuntimeError("division by zero"); - - d3 = d1 / d2; - } + i3 = i1 / i2; } + + else if ( is_unsigned ) + { + if ( u2 == 0 ) + RuntimeError("division by zero"); + + u3 = u1 / u2; + } + else + { + if ( d2 == 0 ) + RuntimeError("division by zero"); + + d3 = d1 / d2; + } + } break; case EXPR_MOD: + { + if ( is_integral ) { - if ( is_integral ) - { - if ( i2 == 0 ) - RuntimeError("modulo by zero"); + if ( i2 == 0 ) + RuntimeError("modulo by zero"); - i3 = i1 % i2; - } - - else if ( is_unsigned ) - { - if ( u2 == 0 ) - RuntimeError("modulo by zero"); - - u3 = u1 % u2; - } - - else - RuntimeErrorWithCallStack("bad type in BinaryExpr::Fold"); + i3 = i1 % i2; } + else if ( is_unsigned ) + { + if ( u2 == 0 ) + RuntimeError("modulo by zero"); + + u3 = u1 % u2; + } + + else + RuntimeErrorWithCallStack("bad type in BinaryExpr::Fold"); + } + break; case EXPR_AND: @@ -1061,13 +1061,13 @@ ValPtr BinaryExpr::StringFold(Val* v1, Val* v2) const case EXPR_ADD: case EXPR_ADD_TO: - { - std::vector strings; - strings.push_back(s1); - strings.push_back(s2); + { + std::vector strings; + strings.push_back(s1); + strings.push_back(s2); - return make_intrusive(concatenate(strings)); - } + return make_intrusive(concatenate(strings)); + } default: BadTag("BinaryExpr::StringFold", expr_name(tag)); @@ -1102,24 +1102,24 @@ ValPtr BinaryExpr::SetFold(Val* v1, Val* v2) const return tv1->Intersection(*tv2); case EXPR_OR: - { - auto rval = v1->Clone(); + { + auto rval = v1->Clone(); - if ( ! tv2->AddTo(rval.get(), false, false) ) - reporter->InternalError("set union failed to type check"); + if ( ! tv2->AddTo(rval.get(), false, false) ) + reporter->InternalError("set union failed to type check"); - return rval; - } + return rval; + } case EXPR_SUB: - { - auto rval = v1->Clone(); + { + auto rval = v1->Clone(); - if ( ! tv2->RemoveFrom(rval.get()) ) - reporter->InternalError("set difference failed to type check"); + if ( ! tv2->RemoveFrom(rval.get()) ) + reporter->InternalError("set difference failed to type check"); - return rval; - } + return rval; + } case EXPR_EQ: res = tv1->EqualTo(*tv2); @@ -3020,15 +3020,15 @@ ValPtr IndexExpr::Fold(Val* v1, Val* v2) const switch ( v1->GetType()->Tag() ) { case TYPE_VECTOR: - { - VectorVal* vect = v1->AsVectorVal(); - const ListVal* lv = v2->AsListVal(); + { + VectorVal* vect = v1->AsVectorVal(); + const ListVal* lv = v2->AsListVal(); - if ( lv->Length() == 1 ) - v = vect->ValAt(lv->Idx(0)->CoerceToUnsigned()); - else - return index_slice(vect, lv); - } + if ( lv->Length() == 1 ) + v = vect->ValAt(lv->Idx(0)->CoerceToUnsigned()); + else + return index_slice(vect, lv); + } break; case TYPE_TABLE: diff --git a/src/Func.cc b/src/Func.cc index 355544362e..d50221132c 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -272,26 +272,25 @@ void Func::CheckPluginResult(bool handled, const ValPtr& hook_result, FunctionFl break; case FUNC_FLAVOR_FUNCTION: + { + const auto& yt = GetType()->Yield(); + + if ( (! yt) || yt->Tag() == TYPE_VOID ) { - const auto& yt = GetType()->Yield(); - - if ( (! yt) || yt->Tag() == TYPE_VOID ) - { - if ( hook_result ) - reporter->InternalError( - "plugin returned non-void result for void method %s", this->Name()); - } - - else if ( hook_result && hook_result->GetType()->Tag() != yt->Tag() && - yt->Tag() != TYPE_ANY ) - { - reporter->InternalError( - "plugin returned wrong type (got %d, expecting %d) for %s", - hook_result->GetType()->Tag(), yt->Tag(), this->Name()); - } - - break; + if ( hook_result ) + reporter->InternalError("plugin returned non-void result for void method %s", + this->Name()); } + + else if ( hook_result && hook_result->GetType()->Tag() != yt->Tag() && + yt->Tag() != TYPE_ANY ) + { + reporter->InternalError("plugin returned wrong type (got %d, expecting %d) for %s", + hook_result->GetType()->Tag(), yt->Tag(), this->Name()); + } + + break; + } } } diff --git a/src/IP.cc b/src/IP.cc index 497d3260d8..ba104277c4 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -58,249 +58,244 @@ RecordValPtr IPv6_Hdr::ToVal(VectorValPtr chain) const switch ( type ) { case IPPROTO_IPV6: - { - static auto ip6_hdr_type = id::find_type("ip6_hdr"); - rv = make_intrusive(ip6_hdr_type); - const struct ip6_hdr* ip6 = (const struct ip6_hdr*)data; - rv->Assign(0, (ntohl(ip6->ip6_flow) & 0x0ff00000) >> 20); - rv->Assign(1, ntohl(ip6->ip6_flow) & 0x000fffff); - rv->Assign(2, ntohs(ip6->ip6_plen)); - rv->Assign(3, ip6->ip6_nxt); - rv->Assign(4, ip6->ip6_hlim); - rv->Assign(5, make_intrusive(IPAddr(ip6->ip6_src))); - rv->Assign(6, make_intrusive(IPAddr(ip6->ip6_dst))); - if ( ! chain ) - chain = - make_intrusive(id::find_type("ip6_ext_hdr_chain")); - rv->Assign(7, std::move(chain)); - } + { + static auto ip6_hdr_type = id::find_type("ip6_hdr"); + rv = make_intrusive(ip6_hdr_type); + const struct ip6_hdr* ip6 = (const struct ip6_hdr*)data; + rv->Assign(0, (ntohl(ip6->ip6_flow) & 0x0ff00000) >> 20); + rv->Assign(1, ntohl(ip6->ip6_flow) & 0x000fffff); + rv->Assign(2, ntohs(ip6->ip6_plen)); + rv->Assign(3, ip6->ip6_nxt); + rv->Assign(4, ip6->ip6_hlim); + rv->Assign(5, make_intrusive(IPAddr(ip6->ip6_src))); + rv->Assign(6, make_intrusive(IPAddr(ip6->ip6_dst))); + if ( ! chain ) + chain = make_intrusive(id::find_type("ip6_ext_hdr_chain")); + rv->Assign(7, std::move(chain)); + } break; case IPPROTO_HOPOPTS: - { - static auto ip6_hopopts_type = id::find_type("ip6_hopopts"); - rv = make_intrusive(ip6_hopopts_type); - const struct ip6_hbh* hbh = (const struct ip6_hbh*)data; - rv->Assign(0, hbh->ip6h_nxt); - rv->Assign(1, hbh->ip6h_len); - uint16_t off = 2 * sizeof(uint8_t); - rv->Assign(2, BuildOptionsVal(data + off, Length() - off)); - } + { + static auto ip6_hopopts_type = id::find_type("ip6_hopopts"); + rv = make_intrusive(ip6_hopopts_type); + const struct ip6_hbh* hbh = (const struct ip6_hbh*)data; + rv->Assign(0, hbh->ip6h_nxt); + rv->Assign(1, hbh->ip6h_len); + uint16_t off = 2 * sizeof(uint8_t); + rv->Assign(2, BuildOptionsVal(data + off, Length() - off)); + } break; case IPPROTO_DSTOPTS: - { - static auto ip6_dstopts_type = id::find_type("ip6_dstopts"); - rv = make_intrusive(ip6_dstopts_type); - const struct ip6_dest* dst = (const struct ip6_dest*)data; - rv->Assign(0, dst->ip6d_nxt); - rv->Assign(1, dst->ip6d_len); - uint16_t off = 2 * sizeof(uint8_t); - rv->Assign(2, BuildOptionsVal(data + off, Length() - off)); - } + { + static auto ip6_dstopts_type = id::find_type("ip6_dstopts"); + rv = make_intrusive(ip6_dstopts_type); + const struct ip6_dest* dst = (const struct ip6_dest*)data; + rv->Assign(0, dst->ip6d_nxt); + rv->Assign(1, dst->ip6d_len); + uint16_t off = 2 * sizeof(uint8_t); + rv->Assign(2, BuildOptionsVal(data + off, Length() - off)); + } break; case IPPROTO_ROUTING: - { - static auto ip6_routing_type = id::find_type("ip6_routing"); - rv = make_intrusive(ip6_routing_type); - const struct ip6_rthdr* rt = (const struct ip6_rthdr*)data; - rv->Assign(0, rt->ip6r_nxt); - rv->Assign(1, rt->ip6r_len); - rv->Assign(2, rt->ip6r_type); - rv->Assign(3, rt->ip6r_segleft); - uint16_t off = 4 * sizeof(uint8_t); - rv->Assign(4, new String(data + off, Length() - off, true)); - } + { + static auto ip6_routing_type = id::find_type("ip6_routing"); + rv = make_intrusive(ip6_routing_type); + const struct ip6_rthdr* rt = (const struct ip6_rthdr*)data; + rv->Assign(0, rt->ip6r_nxt); + rv->Assign(1, rt->ip6r_len); + rv->Assign(2, rt->ip6r_type); + rv->Assign(3, rt->ip6r_segleft); + uint16_t off = 4 * sizeof(uint8_t); + rv->Assign(4, new String(data + off, Length() - off, true)); + } break; case IPPROTO_FRAGMENT: - { - static auto ip6_fragment_type = id::find_type("ip6_fragment"); - rv = make_intrusive(ip6_fragment_type); - const struct ip6_frag* frag = (const struct ip6_frag*)data; - rv->Assign(0, frag->ip6f_nxt); - rv->Assign(1, frag->ip6f_reserved); - rv->Assign(2, (ntohs(frag->ip6f_offlg) & 0xfff8) >> 3); - rv->Assign(3, (ntohs(frag->ip6f_offlg) & 0x0006) >> 1); - rv->Assign(4, static_cast(ntohs(frag->ip6f_offlg) & 0x0001)); - rv->Assign(5, ntohl(frag->ip6f_ident)); - } + { + static auto ip6_fragment_type = id::find_type("ip6_fragment"); + rv = make_intrusive(ip6_fragment_type); + const struct ip6_frag* frag = (const struct ip6_frag*)data; + rv->Assign(0, frag->ip6f_nxt); + rv->Assign(1, frag->ip6f_reserved); + rv->Assign(2, (ntohs(frag->ip6f_offlg) & 0xfff8) >> 3); + rv->Assign(3, (ntohs(frag->ip6f_offlg) & 0x0006) >> 1); + rv->Assign(4, static_cast(ntohs(frag->ip6f_offlg) & 0x0001)); + rv->Assign(5, ntohl(frag->ip6f_ident)); + } break; case IPPROTO_AH: - { - static auto ip6_ah_type = id::find_type("ip6_ah"); - rv = make_intrusive(ip6_ah_type); - rv->Assign(0, ((ip6_ext*)data)->ip6e_nxt); - rv->Assign(1, ((ip6_ext*)data)->ip6e_len); - rv->Assign(2, ntohs(((uint16_t*)data)[1])); - rv->Assign(3, ntohl(((uint32_t*)data)[1])); + { + static auto ip6_ah_type = id::find_type("ip6_ah"); + rv = make_intrusive(ip6_ah_type); + rv->Assign(0, ((ip6_ext*)data)->ip6e_nxt); + rv->Assign(1, ((ip6_ext*)data)->ip6e_len); + rv->Assign(2, ntohs(((uint16_t*)data)[1])); + rv->Assign(3, ntohl(((uint32_t*)data)[1])); - if ( Length() >= 12 ) - { - // Sequence Number and ICV fields can only be extracted if - // Payload Len was non-zero for this header. - rv->Assign(4, ntohl(((uint32_t*)data)[2])); - uint16_t off = 3 * sizeof(uint32_t); - rv->Assign(5, new String(data + off, Length() - off, true)); - } + if ( Length() >= 12 ) + { + // Sequence Number and ICV fields can only be extracted if + // Payload Len was non-zero for this header. + rv->Assign(4, ntohl(((uint32_t*)data)[2])); + uint16_t off = 3 * sizeof(uint32_t); + rv->Assign(5, new String(data + off, Length() - off, true)); } + } break; case IPPROTO_ESP: - { - static auto ip6_esp_type = id::find_type("ip6_esp"); - rv = make_intrusive(ip6_esp_type); - const uint32_t* esp = (const uint32_t*)data; - rv->Assign(0, ntohl(esp[0])); - rv->Assign(1, ntohl(esp[1])); - } + { + static auto ip6_esp_type = id::find_type("ip6_esp"); + rv = make_intrusive(ip6_esp_type); + const uint32_t* esp = (const uint32_t*)data; + rv->Assign(0, ntohl(esp[0])); + rv->Assign(1, ntohl(esp[1])); + } break; case IPPROTO_MOBILITY: + { + static auto ip6_mob_type = id::find_type("ip6_mobility_hdr"); + rv = make_intrusive(ip6_mob_type); + const struct ip6_mobility* mob = (const struct ip6_mobility*)data; + rv->Assign(0, mob->ip6mob_payload); + rv->Assign(1, mob->ip6mob_len); + rv->Assign(2, mob->ip6mob_type); + rv->Assign(3, mob->ip6mob_rsv); + rv->Assign(4, ntohs(mob->ip6mob_chksum)); + + static auto ip6_mob_msg_type = id::find_type("ip6_mobility_msg"); + auto msg = make_intrusive(ip6_mob_msg_type); + msg->Assign(0, mob->ip6mob_type); + + uint16_t off = sizeof(ip6_mobility); + const u_char* msg_data = data + off; + + static auto ip6_mob_brr_type = id::find_type("ip6_mobility_brr"); + static auto ip6_mob_hoti_type = id::find_type("ip6_mobility_hoti"); + static auto ip6_mob_coti_type = id::find_type("ip6_mobility_coti"); + static auto ip6_mob_hot_type = id::find_type("ip6_mobility_hot"); + static auto ip6_mob_cot_type = id::find_type("ip6_mobility_cot"); + static auto ip6_mob_bu_type = id::find_type("ip6_mobility_bu"); + static auto ip6_mob_back_type = id::find_type("ip6_mobility_back"); + static auto ip6_mob_be_type = id::find_type("ip6_mobility_be"); + + switch ( mob->ip6mob_type ) { - static auto ip6_mob_type = id::find_type("ip6_mobility_hdr"); - rv = make_intrusive(ip6_mob_type); - const struct ip6_mobility* mob = (const struct ip6_mobility*)data; - rv->Assign(0, mob->ip6mob_payload); - rv->Assign(1, mob->ip6mob_len); - rv->Assign(2, mob->ip6mob_type); - rv->Assign(3, mob->ip6mob_rsv); - rv->Assign(4, ntohs(mob->ip6mob_chksum)); - - static auto ip6_mob_msg_type = id::find_type("ip6_mobility_msg"); - auto msg = make_intrusive(ip6_mob_msg_type); - msg->Assign(0, mob->ip6mob_type); - - uint16_t off = sizeof(ip6_mobility); - const u_char* msg_data = data + off; - - static auto ip6_mob_brr_type = id::find_type("ip6_mobility_brr"); - static auto ip6_mob_hoti_type = id::find_type("ip6_mobility_hoti"); - static auto ip6_mob_coti_type = id::find_type("ip6_mobility_coti"); - static auto ip6_mob_hot_type = id::find_type("ip6_mobility_hot"); - static auto ip6_mob_cot_type = id::find_type("ip6_mobility_cot"); - static auto ip6_mob_bu_type = id::find_type("ip6_mobility_bu"); - static auto ip6_mob_back_type = id::find_type("ip6_mobility_back"); - static auto ip6_mob_be_type = id::find_type("ip6_mobility_be"); - - switch ( mob->ip6mob_type ) + case 0: { - case 0: - { - auto m = make_intrusive(ip6_mob_brr_type); - m->Assign(0, ntohs(*((uint16_t*)msg_data))); - off += sizeof(uint16_t); - m->Assign(1, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(1, std::move(m)); - } - break; + auto m = make_intrusive(ip6_mob_brr_type); + m->Assign(0, ntohs(*((uint16_t*)msg_data))); + off += sizeof(uint16_t); + m->Assign(1, BuildOptionsVal(data + off, Length() - off)); + msg->Assign(1, std::move(m)); + } + break; - case 1: - { - auto m = make_intrusive(ip6_mob_hoti_type); - m->Assign(0, ntohs(*((uint16_t*)msg_data))); - m->Assign(1, ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t))))); - off += sizeof(uint16_t) + sizeof(uint64_t); - m->Assign(2, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(2, std::move(m)); - break; - } - - case 2: - { - auto m = make_intrusive(ip6_mob_coti_type); - m->Assign(0, ntohs(*((uint16_t*)msg_data))); - m->Assign(1, ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t))))); - off += sizeof(uint16_t) + sizeof(uint64_t); - m->Assign(2, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(3, std::move(m)); - break; - } - - case 3: - { - auto m = make_intrusive(ip6_mob_hot_type); - m->Assign(0, ntohs(*((uint16_t*)msg_data))); - m->Assign(1, ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t))))); - m->Assign(2, ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t) + - sizeof(uint64_t))))); - off += sizeof(uint16_t) + 2 * sizeof(uint64_t); - m->Assign(3, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(4, std::move(m)); - break; - } - - case 4: - { - auto m = make_intrusive(ip6_mob_cot_type); - m->Assign(0, ntohs(*((uint16_t*)msg_data))); - m->Assign(1, ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t))))); - m->Assign(2, ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t) + - sizeof(uint64_t))))); - off += sizeof(uint16_t) + 2 * sizeof(uint64_t); - m->Assign(3, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(5, std::move(m)); - break; - } - - case 5: - { - auto m = make_intrusive(ip6_mob_bu_type); - m->Assign(0, ntohs(*((uint16_t*)msg_data))); - m->Assign(1, static_cast( - ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & - 0x8000)); - m->Assign(2, static_cast( - ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & - 0x4000)); - m->Assign(3, static_cast( - ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & - 0x2000)); - m->Assign(4, static_cast( - ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & - 0x1000)); - m->Assign(5, ntohs(*((uint16_t*)(msg_data + 2 * sizeof(uint16_t))))); - off += 3 * sizeof(uint16_t); - m->Assign(6, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(6, std::move(m)); - break; - } - - case 6: - { - auto m = make_intrusive(ip6_mob_back_type); - m->Assign(0, *((uint8_t*)msg_data)); - m->Assign(1, static_cast( - *((uint8_t*)(msg_data + sizeof(uint8_t))) & 0x80)); - m->Assign(2, ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t))))); - m->Assign(3, ntohs(*((uint16_t*)(msg_data + 2 * sizeof(uint16_t))))); - off += 3 * sizeof(uint16_t); - m->Assign(4, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(7, std::move(m)); - break; - } - - case 7: - { - auto m = make_intrusive(ip6_mob_be_type); - m->Assign(0, *((uint8_t*)msg_data)); - const in6_addr* hoa = (const in6_addr*)(msg_data + sizeof(uint16_t)); - m->Assign(1, make_intrusive(IPAddr(*hoa))); - off += sizeof(uint16_t) + sizeof(in6_addr); - m->Assign(2, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(8, std::move(m)); - break; - } - - default: - reporter->Weird("unknown_mobility_type", util::fmt("%d", mob->ip6mob_type)); - break; + case 1: + { + auto m = make_intrusive(ip6_mob_hoti_type); + m->Assign(0, ntohs(*((uint16_t*)msg_data))); + m->Assign(1, ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t))))); + off += sizeof(uint16_t) + sizeof(uint64_t); + m->Assign(2, BuildOptionsVal(data + off, Length() - off)); + msg->Assign(2, std::move(m)); + break; } - rv->Assign(5, std::move(msg)); + case 2: + { + auto m = make_intrusive(ip6_mob_coti_type); + m->Assign(0, ntohs(*((uint16_t*)msg_data))); + m->Assign(1, ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t))))); + off += sizeof(uint16_t) + sizeof(uint64_t); + m->Assign(2, BuildOptionsVal(data + off, Length() - off)); + msg->Assign(3, std::move(m)); + break; + } + + case 3: + { + auto m = make_intrusive(ip6_mob_hot_type); + m->Assign(0, ntohs(*((uint16_t*)msg_data))); + m->Assign(1, ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t))))); + m->Assign( + 2, ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t) + sizeof(uint64_t))))); + off += sizeof(uint16_t) + 2 * sizeof(uint64_t); + m->Assign(3, BuildOptionsVal(data + off, Length() - off)); + msg->Assign(4, std::move(m)); + break; + } + + case 4: + { + auto m = make_intrusive(ip6_mob_cot_type); + m->Assign(0, ntohs(*((uint16_t*)msg_data))); + m->Assign(1, ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t))))); + m->Assign( + 2, ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t) + sizeof(uint64_t))))); + off += sizeof(uint16_t) + 2 * sizeof(uint64_t); + m->Assign(3, BuildOptionsVal(data + off, Length() - off)); + msg->Assign(5, std::move(m)); + break; + } + + case 5: + { + auto m = make_intrusive(ip6_mob_bu_type); + m->Assign(0, ntohs(*((uint16_t*)msg_data))); + m->Assign(1, static_cast( + ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & 0x8000)); + m->Assign(2, static_cast( + ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & 0x4000)); + m->Assign(3, static_cast( + ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & 0x2000)); + m->Assign(4, static_cast( + ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & 0x1000)); + m->Assign(5, ntohs(*((uint16_t*)(msg_data + 2 * sizeof(uint16_t))))); + off += 3 * sizeof(uint16_t); + m->Assign(6, BuildOptionsVal(data + off, Length() - off)); + msg->Assign(6, std::move(m)); + break; + } + + case 6: + { + auto m = make_intrusive(ip6_mob_back_type); + m->Assign(0, *((uint8_t*)msg_data)); + m->Assign(1, + static_cast(*((uint8_t*)(msg_data + sizeof(uint8_t))) & 0x80)); + m->Assign(2, ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t))))); + m->Assign(3, ntohs(*((uint16_t*)(msg_data + 2 * sizeof(uint16_t))))); + off += 3 * sizeof(uint16_t); + m->Assign(4, BuildOptionsVal(data + off, Length() - off)); + msg->Assign(7, std::move(m)); + break; + } + + case 7: + { + auto m = make_intrusive(ip6_mob_be_type); + m->Assign(0, *((uint8_t*)msg_data)); + const in6_addr* hoa = (const in6_addr*)(msg_data + sizeof(uint16_t)); + m->Assign(1, make_intrusive(IPAddr(*hoa))); + off += sizeof(uint16_t) + sizeof(in6_addr); + m->Assign(2, BuildOptionsVal(data + off, Length() - off)); + msg->Assign(8, std::move(m)); + break; + } + + default: + reporter->Weird("unknown_mobility_type", util::fmt("%d", mob->ip6mob_type)); + break; } + + rv->Assign(5, std::move(msg)); + } break; default: @@ -384,67 +379,67 @@ RecordValPtr IP_Hdr::ToPktHdrVal(RecordValPtr pkt_hdr, int sindex) const switch ( proto ) { case IPPROTO_TCP: - { - const struct tcphdr* tp = (const struct tcphdr*)data; - auto tcp_hdr = make_intrusive(tcp_hdr_type); + { + const struct tcphdr* tp = (const struct tcphdr*)data; + auto tcp_hdr = make_intrusive(tcp_hdr_type); - int tcp_hdr_len = tp->th_off * 4; - int data_len = PayloadLen() - tcp_hdr_len; + int tcp_hdr_len = tp->th_off * 4; + int data_len = PayloadLen() - tcp_hdr_len; - tcp_hdr->Assign(0, val_mgr->Port(ntohs(tp->th_sport), TRANSPORT_TCP)); - tcp_hdr->Assign(1, val_mgr->Port(ntohs(tp->th_dport), TRANSPORT_TCP)); - tcp_hdr->Assign(2, ntohl(tp->th_seq)); - tcp_hdr->Assign(3, ntohl(tp->th_ack)); - tcp_hdr->Assign(4, tcp_hdr_len); - tcp_hdr->Assign(5, data_len); - tcp_hdr->Assign(6, tp->th_x2); - tcp_hdr->Assign(7, tp->th_flags); - tcp_hdr->Assign(8, ntohs(tp->th_win)); + tcp_hdr->Assign(0, val_mgr->Port(ntohs(tp->th_sport), TRANSPORT_TCP)); + tcp_hdr->Assign(1, val_mgr->Port(ntohs(tp->th_dport), TRANSPORT_TCP)); + tcp_hdr->Assign(2, ntohl(tp->th_seq)); + tcp_hdr->Assign(3, ntohl(tp->th_ack)); + tcp_hdr->Assign(4, tcp_hdr_len); + tcp_hdr->Assign(5, data_len); + tcp_hdr->Assign(6, tp->th_x2); + tcp_hdr->Assign(7, tp->th_flags); + tcp_hdr->Assign(8, ntohs(tp->th_win)); - pkt_hdr->Assign(sindex + 2, std::move(tcp_hdr)); - break; - } + pkt_hdr->Assign(sindex + 2, std::move(tcp_hdr)); + break; + } case IPPROTO_UDP: - { - const struct udphdr* up = (const struct udphdr*)data; - auto udp_hdr = make_intrusive(udp_hdr_type); + { + const struct udphdr* up = (const struct udphdr*)data; + auto udp_hdr = make_intrusive(udp_hdr_type); - udp_hdr->Assign(0, val_mgr->Port(ntohs(up->uh_sport), TRANSPORT_UDP)); - udp_hdr->Assign(1, val_mgr->Port(ntohs(up->uh_dport), TRANSPORT_UDP)); - udp_hdr->Assign(2, ntohs(up->uh_ulen)); + udp_hdr->Assign(0, val_mgr->Port(ntohs(up->uh_sport), TRANSPORT_UDP)); + udp_hdr->Assign(1, val_mgr->Port(ntohs(up->uh_dport), TRANSPORT_UDP)); + udp_hdr->Assign(2, ntohs(up->uh_ulen)); - pkt_hdr->Assign(sindex + 3, std::move(udp_hdr)); - break; - } + pkt_hdr->Assign(sindex + 3, std::move(udp_hdr)); + break; + } case IPPROTO_ICMP: - { - const struct icmp* icmpp = (const struct icmp*)data; - auto icmp_hdr = make_intrusive(icmp_hdr_type); + { + const struct icmp* icmpp = (const struct icmp*)data; + auto icmp_hdr = make_intrusive(icmp_hdr_type); - icmp_hdr->Assign(0, icmpp->icmp_type); + icmp_hdr->Assign(0, icmpp->icmp_type); - pkt_hdr->Assign(sindex + 4, std::move(icmp_hdr)); - break; - } + pkt_hdr->Assign(sindex + 4, std::move(icmp_hdr)); + break; + } case IPPROTO_ICMPV6: - { - const struct icmp6_hdr* icmpp = (const struct icmp6_hdr*)data; - auto icmp_hdr = make_intrusive(icmp_hdr_type); + { + const struct icmp6_hdr* icmpp = (const struct icmp6_hdr*)data; + auto icmp_hdr = make_intrusive(icmp_hdr_type); - icmp_hdr->Assign(0, icmpp->icmp6_type); + icmp_hdr->Assign(0, icmpp->icmp6_type); - pkt_hdr->Assign(sindex + 4, std::move(icmp_hdr)); - break; - } + pkt_hdr->Assign(sindex + 4, std::move(icmp_hdr)); + break; + } default: - { - // This is not a protocol we understand. - break; - } + { + // This is not a protocol we understand. + break; + } } return pkt_hdr; @@ -585,30 +580,30 @@ void IPv6_Hdr_Chain::ProcessRoutingHeader(const struct ip6_rthdr* r, uint16_t le switch ( r->ip6r_type ) { case 0: // Defined by RFC 2460, deprecated by RFC 5095 + { + if ( r->ip6r_segleft > 0 && r->ip6r_len >= 2 ) { - if ( r->ip6r_segleft > 0 && r->ip6r_len >= 2 ) - { - if ( r->ip6r_len % 2 == 0 ) - finalDst = new IPAddr(*addr); - else - reporter->Weird(SrcAddr(), DstAddr(), "odd_routing0_len"); - } - - // Always raise a weird since this type is deprecated. - reporter->Weird(SrcAddr(), DstAddr(), "routing0_hdr"); + if ( r->ip6r_len % 2 == 0 ) + finalDst = new IPAddr(*addr); + else + reporter->Weird(SrcAddr(), DstAddr(), "odd_routing0_len"); } + + // Always raise a weird since this type is deprecated. + reporter->Weird(SrcAddr(), DstAddr(), "routing0_hdr"); + } break; case 2: // Defined by Mobile IPv6 RFC 6275. + { + if ( r->ip6r_segleft > 0 ) { - if ( r->ip6r_segleft > 0 ) - { - if ( r->ip6r_len == 2 ) - finalDst = new IPAddr(*addr); - else - reporter->Weird(SrcAddr(), DstAddr(), "bad_routing2_len"); - } + if ( r->ip6r_len == 2 ) + finalDst = new IPAddr(*addr); + else + reporter->Weird(SrcAddr(), DstAddr(), "bad_routing2_len"); } + } break; default: @@ -642,36 +637,35 @@ void IPv6_Hdr_Chain::ProcessDstOpts(const struct ip6_dest* d, uint16_t len) len -= sizeof(uint8_t); break; default: + { + // Double-check that the len can hold the whole option structure. + // Otherwise we get a buffer-overflow when we check the option_len. + // Also check that it holds everything for the option itself. + if ( len < sizeof(struct ip6_opt) || len < sizeof(struct ip6_opt) + opt->ip6o_len ) { - // Double-check that the len can hold the whole option structure. - // Otherwise we get a buffer-overflow when we check the option_len. - // Also check that it holds everything for the option itself. - if ( len < sizeof(struct ip6_opt) || - len < sizeof(struct ip6_opt) + opt->ip6o_len ) - { - reporter->Weird(SrcAddr(), DstAddr(), "bad_ipv6_dest_opt_len"); - len = 0; - break; - } - - if ( opt->ip6o_type == - 201 ) // Home Address Option, Mobile IPv6 RFC 6275 section 6.3 - { - if ( opt->ip6o_len == sizeof(struct in6_addr) ) - { - if ( homeAddr ) - reporter->Weird(SrcAddr(), DstAddr(), "multiple_home_addr_opts"); - else - homeAddr = - new IPAddr(*((const in6_addr*)(data + sizeof(struct ip6_opt)))); - } - else - reporter->Weird(SrcAddr(), DstAddr(), "bad_home_addr_len"); - } - - data += sizeof(struct ip6_opt) + opt->ip6o_len; - len -= sizeof(struct ip6_opt) + opt->ip6o_len; + reporter->Weird(SrcAddr(), DstAddr(), "bad_ipv6_dest_opt_len"); + len = 0; + break; } + + if ( opt->ip6o_type == + 201 ) // Home Address Option, Mobile IPv6 RFC 6275 section 6.3 + { + if ( opt->ip6o_len == sizeof(struct in6_addr) ) + { + if ( homeAddr ) + reporter->Weird(SrcAddr(), DstAddr(), "multiple_home_addr_opts"); + else + homeAddr = + new IPAddr(*((const in6_addr*)(data + sizeof(struct ip6_opt)))); + } + else + reporter->Weird(SrcAddr(), DstAddr(), "bad_home_addr_len"); + } + + data += sizeof(struct ip6_opt) + opt->ip6o_len; + len -= sizeof(struct ip6_opt) + opt->ip6o_len; + } break; } } diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index d8d709cdf0..9e00e3aa70 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -1285,38 +1285,38 @@ static bool val_to_maskedval(Val* v, maskedvalue_list* append_to, vectorpush_back(v->AsSubNet()); + delete mval; + return true; + } + else + { + const uint32_t* n; + uint32_t m[4]; + v->AsSubNet().Prefix().GetBytes(&n); + v->AsSubNetVal()->Mask().CopyIPv6(m); + + for ( unsigned int i = 0; i < 4; ++i ) + m[i] = ntohl(m[i]); + + bool is_v4_mask = m[0] == 0xffffffff && m[1] == m[0] && m[2] == m[0]; + + if ( v->AsSubNet().Prefix().GetFamily() == IPv4 && is_v4_mask ) { - prefix_vector->push_back(v->AsSubNet()); - delete mval; - return true; + mval->val = ntohl(*n); + mval->mask = m[3]; } else { - const uint32_t* n; - uint32_t m[4]; - v->AsSubNet().Prefix().GetBytes(&n); - v->AsSubNetVal()->Mask().CopyIPv6(m); - - for ( unsigned int i = 0; i < 4; ++i ) - m[i] = ntohl(m[i]); - - bool is_v4_mask = m[0] == 0xffffffff && m[1] == m[0] && m[2] == m[0]; - - if ( v->AsSubNet().Prefix().GetFamily() == IPv4 && is_v4_mask ) - { - mval->val = ntohl(*n); - mval->mask = m[3]; - } - else - { - rules_error("IPv6 subnets not supported"); - mval->val = 0; - mval->mask = 0; - } + rules_error("IPv6 subnets not supported"); + mval->val = 0; + mval->mask = 0; } } + } break; default: diff --git a/src/Stmt.cc b/src/Stmt.cc index e2a01395b8..257b2fd7a1 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -353,10 +353,10 @@ void do_print_stmt(const std::vector& vals) case BifEnum::Log::REDIRECT_NONE: break; case BifEnum::Log::REDIRECT_ALL: - { - print_log(vals); - return; - } + { + print_log(vals); + return; + } case BifEnum::Log::REDIRECT_STDOUT: if ( f->FileHandle() == stdout ) { @@ -765,35 +765,35 @@ SwitchStmt::SwitchStmt(ExprPtr index, case_list* arg_cases) { // Simplify trivial unary plus/minus expressions on consts. case EXPR_NEGATE: - { - NegExpr* ne = (NegExpr*)(expr); + { + NegExpr* ne = (NegExpr*)(expr); - if ( ne->Op()->IsConst() ) - Unref(exprs.replace(j, new ConstExpr(ne->Eval(nullptr)))); - } + if ( ne->Op()->IsConst() ) + Unref(exprs.replace(j, new ConstExpr(ne->Eval(nullptr)))); + } break; case EXPR_POSITIVE: - { - PosExpr* pe = (PosExpr*)(expr); + { + PosExpr* pe = (PosExpr*)(expr); - if ( pe->Op()->IsConst() ) - Unref(exprs.replace(j, new ConstExpr(pe->Eval(nullptr)))); - } + if ( pe->Op()->IsConst() ) + Unref(exprs.replace(j, new ConstExpr(pe->Eval(nullptr)))); + } break; case EXPR_NAME: + { + NameExpr* ne = (NameExpr*)(expr); + + if ( ne->Id()->IsConst() ) { - NameExpr* ne = (NameExpr*)(expr); + auto v = ne->Eval(nullptr); - if ( ne->Id()->IsConst() ) - { - auto v = ne->Eval(nullptr); - - if ( v ) - Unref(exprs.replace(j, new ConstExpr(std::move(v)))); - } + if ( v ) + Unref(exprs.replace(j, new ConstExpr(std::move(v)))); } + } break; default: diff --git a/src/Trigger.cc b/src/Trigger.cc index ba1aa31d23..ba9825071f 100644 --- a/src/Trigger.cc +++ b/src/Trigger.cc @@ -48,17 +48,17 @@ TraversalCode trigger::TriggerTraversalCallback::PreExpr(const Expr* expr) switch ( expr->Tag() ) { case EXPR_NAME: - { - const auto* e = static_cast(expr); - if ( e->Id()->IsGlobal() ) - trigger->Register(e->Id()); + { + const auto* e = static_cast(expr); + if ( e->Id()->IsGlobal() ) + trigger->Register(e->Id()); - Val* v = e->Id()->GetVal().get(); + Val* v = e->Id()->GetVal().get(); - if ( v && v->Modifiable() ) - trigger->Register(v); - break; - }; + if ( v && v->Modifiable() ) + trigger->Register(v); + break; + }; default: // All others are uninteresting. diff --git a/src/Type.cc b/src/Type.cc index 0d3a6e10cc..7e04f80f74 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -459,39 +459,39 @@ static bool is_supported_index_type(const TypePtr& t, const char** tname) return true; case TYPE_RECORD: - { - auto rt = t->AsRecordType(); + { + auto rt = t->AsRecordType(); - for ( auto i = 0; i < rt->NumFields(); ++i ) - if ( ! is_supported_index_type(rt->GetFieldType(i), tname) ) - return false; - - return true; - } - - case TYPE_LIST: - { - for ( const auto& type : t->AsTypeList()->GetTypes() ) - if ( ! is_supported_index_type(type, tname) ) - return false; - - return true; - } - - case TYPE_TABLE: - { - auto tt = t->AsTableType(); - - if ( ! is_supported_index_type(tt->GetIndices(), tname) ) + for ( auto i = 0; i < rt->NumFields(); ++i ) + if ( ! is_supported_index_type(rt->GetFieldType(i), tname) ) return false; - const auto& yt = tt->Yield(); + return true; + } - if ( ! yt ) - return true; + case TYPE_LIST: + { + for ( const auto& type : t->AsTypeList()->GetTypes() ) + if ( ! is_supported_index_type(type, tname) ) + return false; - return is_supported_index_type(yt, tname); - } + return true; + } + + case TYPE_TABLE: + { + auto tt = t->AsTableType(); + + if ( ! is_supported_index_type(tt->GetIndices(), tname) ) + return false; + + const auto& yt = tt->Yield(); + + if ( ! yt ) + return true; + + return is_supported_index_type(yt, tname); + } case TYPE_VECTOR: return is_supported_index_type(t->AsVectorType()->Yield(), tname); @@ -1254,23 +1254,23 @@ void RecordType::Create(std::vector>& r) const break; case FieldInit::R_INIT_DEF: + { + auto v = init->def_expr->Eval(nullptr); + if ( v ) { - auto v = init->def_expr->Eval(nullptr); - if ( v ) + const auto& t = init->def_type; + + if ( init->def_coerce ) { - const auto& t = init->def_type; - - if ( init->def_coerce ) - { - auto rt = cast_intrusive(t); - v = v->AsRecordVal()->CoerceTo(rt); - } - - r_i = ZVal(v, t); + auto rt = cast_intrusive(t); + v = v->AsRecordVal()->CoerceTo(rt); } - else - reporter->Error("failed &default in record creation"); + + r_i = ZVal(v, t); } + else + reporter->Error("failed &default in record creation"); + } break; case FieldInit::R_INIT_RECORD: @@ -1904,81 +1904,81 @@ bool same_type(const Type& arg_t1, const Type& arg_t2, bool is_init, bool match_ return true; case TYPE_OPAQUE: - { - const OpaqueType* ot1 = (const OpaqueType*)t1; - const OpaqueType* ot2 = (const OpaqueType*)t2; - return ot1->Name() == ot2->Name(); - } + { + const OpaqueType* ot1 = (const OpaqueType*)t1; + const OpaqueType* ot2 = (const OpaqueType*)t2; + return ot1->Name() == ot2->Name(); + } case TYPE_TABLE: - { - const IndexType* it1 = (const IndexType*)t1; - const IndexType* it2 = (const IndexType*)t2; + { + const IndexType* it1 = (const IndexType*)t1; + const IndexType* it2 = (const IndexType*)t2; - const auto& tl1 = it1->GetIndices(); - const auto& tl2 = it2->GetIndices(); + const auto& tl1 = it1->GetIndices(); + const auto& tl2 = it2->GetIndices(); - if ( (tl1 || tl2) && ! (tl1 && tl2) ) - return false; + if ( (tl1 || tl2) && ! (tl1 && tl2) ) + return false; - const auto& y1 = t1->Yield(); - const auto& y2 = t2->Yield(); + const auto& y1 = t1->Yield(); + const auto& y2 = t2->Yield(); - if ( (y1 || y2) && ! (y1 && y2) ) - return false; + if ( (y1 || y2) && ! (y1 && y2) ) + return false; - break; - } + break; + } case TYPE_FUNC: - { - const FuncType* ft1 = (const FuncType*)t1; - const FuncType* ft2 = (const FuncType*)t2; + { + const FuncType* ft1 = (const FuncType*)t1; + const FuncType* ft2 = (const FuncType*)t2; - if ( ft1->Flavor() != ft2->Flavor() ) - return false; + if ( ft1->Flavor() != ft2->Flavor() ) + return false; - const auto& y1 = t1->Yield(); - const auto& y2 = t2->Yield(); - if ( (y1 || y2) && ! (y1 && y2) ) - return false; + const auto& y1 = t1->Yield(); + const auto& y2 = t2->Yield(); + if ( (y1 || y2) && ! (y1 && y2) ) + return false; - break; - } + break; + } case TYPE_RECORD: - { - const RecordType* rt1 = (const RecordType*)t1; - const RecordType* rt2 = (const RecordType*)t2; + { + const RecordType* rt1 = (const RecordType*)t1; + const RecordType* rt2 = (const RecordType*)t2; - if ( rt1->NumFields() != rt2->NumFields() ) + if ( rt1->NumFields() != rt2->NumFields() ) + return false; + + for ( int i = 0; i < rt1->NumFields(); ++i ) + { + const TypeDecl* td1 = rt1->FieldDecl(i); + const TypeDecl* td2 = rt2->FieldDecl(i); + + if ( match_record_field_names && ! util::streq(td1->id, td2->id) ) return false; - for ( int i = 0; i < rt1->NumFields(); ++i ) - { - const TypeDecl* td1 = rt1->FieldDecl(i); - const TypeDecl* td2 = rt2->FieldDecl(i); - - if ( match_record_field_names && ! util::streq(td1->id, td2->id) ) - return false; - - if ( ! same_attrs(td1->attrs.get(), td2->attrs.get()) ) - return false; - } - - break; + if ( ! same_attrs(td1->attrs.get(), td2->attrs.get()) ) + return false; } + break; + } + case TYPE_LIST: - { - const auto& tl1 = t1->AsTypeList()->GetTypes(); - const auto& tl2 = t2->AsTypeList()->GetTypes(); + { + const auto& tl1 = t1->AsTypeList()->GetTypes(); + const auto& tl2 = t2->AsTypeList()->GetTypes(); - if ( tl1.size() != tl2.size() ) - return false; + if ( tl1.size() != tl2.size() ) + return false; - break; - } + break; + } case TYPE_VECTOR: case TYPE_FILE: @@ -2024,73 +2024,73 @@ bool same_type(const Type& arg_t1, const Type& arg_t2, bool is_init, bool match_ switch ( t1->Tag() ) { case TYPE_TABLE: + { + const IndexType* it1 = (const IndexType*)t1; + const IndexType* it2 = (const IndexType*)t2; + + const auto& tl1 = it1->GetIndices(); + const auto& tl2 = it2->GetIndices(); + + if ( ! same_type(tl1, tl2, is_init, match_record_field_names) ) + result = false; + else { - const IndexType* it1 = (const IndexType*)t1; - const IndexType* it2 = (const IndexType*)t2; + const auto& y1 = t1->Yield(); + const auto& y2 = t2->Yield(); - const auto& tl1 = it1->GetIndices(); - const auto& tl2 = it2->GetIndices(); - - if ( ! same_type(tl1, tl2, is_init, match_record_field_names) ) - result = false; - else - { - const auto& y1 = t1->Yield(); - const auto& y2 = t2->Yield(); - - result = same_type(y1, y2, is_init, match_record_field_names); - } - break; + result = same_type(y1, y2, is_init, match_record_field_names); } + break; + } case TYPE_FUNC: - { - const FuncType* ft1 = (const FuncType*)t1; - const FuncType* ft2 = (const FuncType*)t2; + { + const FuncType* ft1 = (const FuncType*)t1; + const FuncType* ft2 = (const FuncType*)t2; - if ( ! same_type(t1->Yield(), t2->Yield(), is_init, match_record_field_names) ) - result = false; - else - result = ft1->CheckArgs(ft2->ParamList()->GetTypes(), is_init, false); - break; - } + if ( ! same_type(t1->Yield(), t2->Yield(), is_init, match_record_field_names) ) + result = false; + else + result = ft1->CheckArgs(ft2->ParamList()->GetTypes(), is_init, false); + break; + } case TYPE_RECORD: + { + const RecordType* rt1 = (const RecordType*)t1; + const RecordType* rt2 = (const RecordType*)t2; + + result = true; + + for ( int i = 0; i < rt1->NumFields(); ++i ) { - const RecordType* rt1 = (const RecordType*)t1; - const RecordType* rt2 = (const RecordType*)t2; + const TypeDecl* td1 = rt1->FieldDecl(i); + const TypeDecl* td2 = rt2->FieldDecl(i); - result = true; - - for ( int i = 0; i < rt1->NumFields(); ++i ) + if ( ! same_type(td1->type, td2->type, is_init, match_record_field_names) ) { - const TypeDecl* td1 = rt1->FieldDecl(i); - const TypeDecl* td2 = rt2->FieldDecl(i); - - if ( ! same_type(td1->type, td2->type, is_init, match_record_field_names) ) - { - result = false; - break; - } + result = false; + break; } - break; } + break; + } case TYPE_LIST: - { - const auto& tl1 = t1->AsTypeList()->GetTypes(); - const auto& tl2 = t2->AsTypeList()->GetTypes(); + { + const auto& tl1 = t1->AsTypeList()->GetTypes(); + const auto& tl2 = t2->AsTypeList()->GetTypes(); - result = true; + result = true; - for ( auto i = 0u; i < tl1.size(); ++i ) - if ( ! same_type(tl1[i], tl2[i], is_init, match_record_field_names) ) - { - result = false; - break; - } - break; - } + for ( auto i = 0u; i < tl1.size(); ++i ) + if ( ! same_type(tl1[i], tl2[i], is_init, match_record_field_names) ) + { + result = false; + break; + } + break; + } case TYPE_VECTOR: case TYPE_FILE: @@ -2098,13 +2098,12 @@ bool same_type(const Type& arg_t1, const Type& arg_t2, bool is_init, bool match_ break; case TYPE_TYPE: - { - auto tt1 = t1->AsTypeType(); - auto tt2 = t2->AsTypeType(); - result = - same_type(tt1->GetType(), tt1->GetType(), is_init, match_record_field_names); - break; - } + { + auto tt1 = t1->AsTypeType(); + auto tt2 = t2->AsTypeType(); + result = same_type(tt1->GetType(), tt1->GetType(), is_init, match_record_field_names); + break; + } default: result = false; @@ -2287,180 +2286,180 @@ TypePtr merge_types(const TypePtr& arg_t1, const TypePtr& arg_t2) return base_type(tg1); case TYPE_ENUM: + { + // Could compare pointers t1 == t2, but maybe there's someone out + // there creating clones of the type, so safer to compare name. + if ( t1->GetName() != t2->GetName() ) { - // Could compare pointers t1 == t2, but maybe there's someone out - // there creating clones of the type, so safer to compare name. - if ( t1->GetName() != t2->GetName() ) - { - std::string msg = util::fmt("incompatible enum types: '%s' and '%s'", - t1->GetName().data(), t2->GetName().data()); + std::string msg = util::fmt("incompatible enum types: '%s' and '%s'", + t1->GetName().data(), t2->GetName().data()); - t1->Error(msg.data(), t2); - return nullptr; - } - - // Doing a lookup here as a roundabout way of ref-ing t1, without - // changing the function params which has t1 as const and also - // (potentially) avoiding a pitfall mentioned earlier about clones. - const auto& id = detail::global_scope()->Find(t1->GetName()); - - if ( id && id->IsType() && id->GetType()->Tag() == TYPE_ENUM ) - // It should make most sense to return the real type here rather - // than a copy since it may be redef'd later in parsing. If we - // return a copy, then whoever is using this return value won't - // actually see those changes from the redef. - return id->GetType(); - - std::string msg = - util::fmt("incompatible enum types: '%s' and '%s'" - " ('%s' enum type ID is invalid)", - t1->GetName().data(), t2->GetName().data(), t1->GetName().data()); t1->Error(msg.data(), t2); return nullptr; } + // Doing a lookup here as a roundabout way of ref-ing t1, without + // changing the function params which has t1 as const and also + // (potentially) avoiding a pitfall mentioned earlier about clones. + const auto& id = detail::global_scope()->Find(t1->GetName()); + + if ( id && id->IsType() && id->GetType()->Tag() == TYPE_ENUM ) + // It should make most sense to return the real type here rather + // than a copy since it may be redef'd later in parsing. If we + // return a copy, then whoever is using this return value won't + // actually see those changes from the redef. + return id->GetType(); + + std::string msg = + util::fmt("incompatible enum types: '%s' and '%s'" + " ('%s' enum type ID is invalid)", + t1->GetName().data(), t2->GetName().data(), t1->GetName().data()); + t1->Error(msg.data(), t2); + return nullptr; + } + case TYPE_TABLE: + { + const IndexType* it1 = (const IndexType*)t1; + const IndexType* it2 = (const IndexType*)t2; + + const auto& tl1 = it1->GetIndexTypes(); + const auto& tl2 = it2->GetIndexTypes(); + TypeListPtr tl3; + + if ( tl1.size() != tl2.size() ) { - const IndexType* it1 = (const IndexType*)t1; - const IndexType* it2 = (const IndexType*)t2; + t1->Error("incompatible types", t2); + return nullptr; + } - const auto& tl1 = it1->GetIndexTypes(); - const auto& tl2 = it2->GetIndexTypes(); - TypeListPtr tl3; + tl3 = make_intrusive(); - if ( tl1.size() != tl2.size() ) + for ( auto i = 0u; i < tl1.size(); ++i ) + { + auto tl3_i = merge_types(tl1[i], tl2[i]); + if ( ! tl3_i ) + return nullptr; + + tl3->Append(std::move(tl3_i)); + } + + const auto& y1 = t1->Yield(); + const auto& y2 = t2->Yield(); + TypePtr y3; + + if ( y1 || y2 ) + { + if ( ! y1 || ! y2 ) { t1->Error("incompatible types", t2); return nullptr; } - tl3 = make_intrusive(); - - for ( auto i = 0u; i < tl1.size(); ++i ) - { - auto tl3_i = merge_types(tl1[i], tl2[i]); - if ( ! tl3_i ) - return nullptr; - - tl3->Append(std::move(tl3_i)); - } - - const auto& y1 = t1->Yield(); - const auto& y2 = t2->Yield(); - TypePtr y3; - - if ( y1 || y2 ) - { - if ( ! y1 || ! y2 ) - { - t1->Error("incompatible types", t2); - return nullptr; - } - - y3 = merge_types(y1, y2); - if ( ! y3 ) - return nullptr; - } - - if ( t1->IsSet() ) - return make_intrusive(std::move(tl3), nullptr); - else - return make_intrusive(std::move(tl3), std::move(y3)); + y3 = merge_types(y1, y2); + if ( ! y3 ) + return nullptr; } + if ( t1->IsSet() ) + return make_intrusive(std::move(tl3), nullptr); + else + return make_intrusive(std::move(tl3), std::move(y3)); + } + case TYPE_FUNC: + { + if ( ! same_type(t1, t2) ) { - if ( ! same_type(t1, t2) ) - { - t1->Error("incompatible types", t2); - return nullptr; - } - - const FuncType* ft1 = (const FuncType*)t1; - const FuncType* ft2 = (const FuncType*)t1; - auto args = cast_intrusive(merge_types(ft1->Params(), ft2->Params())); - auto yield = t1->Yield() ? merge_types(t1->Yield(), t2->Yield()) : nullptr; - - return make_intrusive(std::move(args), std::move(yield), ft1->Flavor()); + t1->Error("incompatible types", t2); + return nullptr; } + const FuncType* ft1 = (const FuncType*)t1; + const FuncType* ft2 = (const FuncType*)t1; + auto args = cast_intrusive(merge_types(ft1->Params(), ft2->Params())); + auto yield = t1->Yield() ? merge_types(t1->Yield(), t2->Yield()) : nullptr; + + return make_intrusive(std::move(args), std::move(yield), ft1->Flavor()); + } + case TYPE_RECORD: + { + const RecordType* rt1 = (const RecordType*)t1; + const RecordType* rt2 = (const RecordType*)t2; + + if ( rt1->NumFields() != rt2->NumFields() ) + return nullptr; + + type_decl_list* tdl3 = new type_decl_list(rt1->NumFields()); + + for ( int i = 0; i < rt1->NumFields(); ++i ) { - const RecordType* rt1 = (const RecordType*)t1; - const RecordType* rt2 = (const RecordType*)t2; + const TypeDecl* td1 = rt1->FieldDecl(i); + const TypeDecl* td2 = rt2->FieldDecl(i); + auto tdl3_i = merge_types(td1->type, td2->type); - if ( rt1->NumFields() != rt2->NumFields() ) - return nullptr; - - type_decl_list* tdl3 = new type_decl_list(rt1->NumFields()); - - for ( int i = 0; i < rt1->NumFields(); ++i ) + if ( ! util::streq(td1->id, td2->id) || ! tdl3_i ) { - const TypeDecl* td1 = rt1->FieldDecl(i); - const TypeDecl* td2 = rt2->FieldDecl(i); - auto tdl3_i = merge_types(td1->type, td2->type); - - if ( ! util::streq(td1->id, td2->id) || ! tdl3_i ) - { - t1->Error("incompatible record fields", t2); - delete tdl3; - return nullptr; - } - - tdl3->push_back(new TypeDecl(util::copy_string(td1->id), std::move(tdl3_i))); + t1->Error("incompatible record fields", t2); + delete tdl3; + return nullptr; } - return make_intrusive(tdl3); + tdl3->push_back(new TypeDecl(util::copy_string(td1->id), std::move(tdl3_i))); } + return make_intrusive(tdl3); + } + case TYPE_LIST: + { + const TypeList* tl1 = t1->AsTypeList(); + const TypeList* tl2 = t2->AsTypeList(); + + if ( tl1->IsPure() != tl2->IsPure() ) { - const TypeList* tl1 = t1->AsTypeList(); - const TypeList* tl2 = t2->AsTypeList(); - - if ( tl1->IsPure() != tl2->IsPure() ) - { - tl1->Error("incompatible lists", tl2); - return nullptr; - } - - const auto& l1 = tl1->GetTypes(); - const auto& l2 = tl2->GetTypes(); - - if ( l1.size() == 0 || l2.size() == 0 ) - { - if ( l1.size() == 0 ) - tl1->Error("empty list"); - else - tl2->Error("empty list"); - return nullptr; - } - - if ( tl1->IsPure() ) - { - // We will be expanding the pure list when converting - // the initialization expression into a set of values. - // So the merge type of the list is the type of one - // of the elements, providing they're consistent. - return merge_types(l1[0], l2[0]); - } - - // Impure lists - must have the same size and match element - // by element. - if ( l1.size() != l2.size() ) - { - tl1->Error("different number of indices", tl2); - return nullptr; - } - - auto tl3 = make_intrusive(); - - for ( auto i = 0u; i < l1.size(); ++i ) - tl3->Append(merge_types(l1[i], l2[i])); - - return tl3; + tl1->Error("incompatible lists", tl2); + return nullptr; } + const auto& l1 = tl1->GetTypes(); + const auto& l2 = tl2->GetTypes(); + + if ( l1.size() == 0 || l2.size() == 0 ) + { + if ( l1.size() == 0 ) + tl1->Error("empty list"); + else + tl2->Error("empty list"); + return nullptr; + } + + if ( tl1->IsPure() ) + { + // We will be expanding the pure list when converting + // the initialization expression into a set of values. + // So the merge type of the list is the type of one + // of the elements, providing they're consistent. + return merge_types(l1[0], l2[0]); + } + + // Impure lists - must have the same size and match element + // by element. + if ( l1.size() != l2.size() ) + { + tl1->Error("different number of indices", tl2); + return nullptr; + } + + auto tl3 = make_intrusive(); + + for ( auto i = 0u; i < l1.size(); ++i ) + tl3->Append(merge_types(l1[i], l2[i])); + + return tl3; + } + case TYPE_VECTOR: if ( ! same_type(t1->Yield(), t2->Yield()) ) { diff --git a/src/Val.cc b/src/Val.cc index 294ffebd5a..3fa01f64c1 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -444,161 +444,161 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* break; case TYPE_PORT: - { - auto* pval = val->AsPortVal(); - writer.StartObject(); - writer.Key("port"); - writer.Int64(pval->Port()); - writer.Key("proto"); - writer.String(pval->Protocol()); - writer.EndObject(); - break; - } + { + auto* pval = val->AsPortVal(); + writer.StartObject(); + writer.Key("port"); + writer.Int64(pval->Port()); + writer.Key("proto"); + writer.String(pval->Protocol()); + writer.EndObject(); + break; + } case TYPE_PATTERN: case TYPE_INTERVAL: case TYPE_ADDR: case TYPE_SUBNET: - { - ODesc d; - d.SetStyle(RAW_STYLE); - val->Describe(&d); - writer.String(reinterpret_cast(d.Bytes()), d.Len()); - break; - } + { + ODesc d; + d.SetStyle(RAW_STYLE); + val->Describe(&d); + writer.String(reinterpret_cast(d.Bytes()), d.Len()); + break; + } case TYPE_FILE: case TYPE_FUNC: case TYPE_ENUM: case TYPE_STRING: - { - ODesc d; - d.SetStyle(RAW_STYLE); - val->Describe(&d); - writer.String(util::json_escape_utf8( - std::string(reinterpret_cast(d.Bytes()), d.Len()))); - break; - } + { + ODesc d; + d.SetStyle(RAW_STYLE); + val->Describe(&d); + writer.String(util::json_escape_utf8( + std::string(reinterpret_cast(d.Bytes()), d.Len()))); + break; + } case TYPE_TABLE: + { + auto* table = val->AsTable(); + auto* tval = val->AsTableVal(); + + if ( tval->GetType()->IsSet() ) + writer.StartArray(); + else + writer.StartObject(); + + std::unique_ptr k; + TableEntryVal* entry; + + for ( const auto& te : *table ) { - auto* table = val->AsTable(); - auto* tval = val->AsTableVal(); + entry = te.GetValue(); + k = te.GetHashKey(); + + auto lv = tval->RecreateIndex(*k); + Val* entry_key = lv->Length() == 1 ? lv->Idx(0).get() : lv.get(); if ( tval->GetType()->IsSet() ) - writer.StartArray(); + BuildJSON(writer, entry_key, only_loggable, re); else - writer.StartObject(); - - std::unique_ptr k; - TableEntryVal* entry; - - for ( const auto& te : *table ) { - entry = te.GetValue(); - k = te.GetHashKey(); + rapidjson::StringBuffer buffer; + threading::formatter::JSON::NullDoubleWriter key_writer(buffer); + BuildJSON(key_writer, entry_key, only_loggable, re); + string key_str = buffer.GetString(); - auto lv = tval->RecreateIndex(*k); - Val* entry_key = lv->Length() == 1 ? lv->Idx(0).get() : lv.get(); + if ( key_str.length() >= 2 && key_str[0] == '"' && + key_str[key_str.length() - 1] == '"' ) + // Strip quotes. + key_str = key_str.substr(1, key_str.length() - 2); - if ( tval->GetType()->IsSet() ) - BuildJSON(writer, entry_key, only_loggable, re); - else - { - rapidjson::StringBuffer buffer; - threading::formatter::JSON::NullDoubleWriter key_writer(buffer); - BuildJSON(key_writer, entry_key, only_loggable, re); - string key_str = buffer.GetString(); - - if ( key_str.length() >= 2 && key_str[0] == '"' && - key_str[key_str.length() - 1] == '"' ) - // Strip quotes. - key_str = key_str.substr(1, key_str.length() - 2); - - BuildJSON(writer, entry->GetVal().get(), only_loggable, re, key_str); - } + BuildJSON(writer, entry->GetVal().get(), only_loggable, re, key_str); } - - if ( tval->GetType()->IsSet() ) - writer.EndArray(); - else - writer.EndObject(); - - break; } + if ( tval->GetType()->IsSet() ) + writer.EndArray(); + else + writer.EndObject(); + + break; + } + case TYPE_RECORD: + { + writer.StartObject(); + + auto* rval = val->AsRecordVal(); + auto rt = rval->GetType()->AsRecordType(); + + for ( auto i = 0; i < rt->NumFields(); ++i ) { - writer.StartObject(); + auto value = rval->GetFieldOrDefault(i); - auto* rval = val->AsRecordVal(); - auto rt = rval->GetType()->AsRecordType(); - - for ( auto i = 0; i < rt->NumFields(); ++i ) + if ( value && (! only_loggable || rt->FieldHasAttr(i, detail::ATTR_LOG)) ) { - auto value = rval->GetFieldOrDefault(i); + string key_str; + auto field_name = rt->FieldName(i); - if ( value && (! only_loggable || rt->FieldHasAttr(i, detail::ATTR_LOG)) ) + if ( re && re->MatchAnywhere(field_name) != 0 ) { - string key_str; - auto field_name = rt->FieldName(i); - - if ( re && re->MatchAnywhere(field_name) != 0 ) - { - auto blank = make_intrusive(""); - auto fn_val = make_intrusive(field_name); - const auto& bs = *blank->AsString(); - auto key_val = fn_val->Replace(re, bs, false); - key_str = key_val->ToStdString(); - } - else - key_str = field_name; - - BuildJSON(writer, value.get(), only_loggable, re, key_str); + auto blank = make_intrusive(""); + auto fn_val = make_intrusive(field_name); + const auto& bs = *blank->AsString(); + auto key_val = fn_val->Replace(re, bs, false); + key_str = key_val->ToStdString(); } - } + else + key_str = field_name; - writer.EndObject(); - break; + BuildJSON(writer, value.get(), only_loggable, re, key_str); + } } + writer.EndObject(); + break; + } + case TYPE_LIST: - { - writer.StartArray(); + { + writer.StartArray(); - auto* lval = val->AsListVal(); - size_t size = lval->Length(); - for ( size_t i = 0; i < size; i++ ) - BuildJSON(writer, lval->Idx(i).get(), only_loggable, re); + auto* lval = val->AsListVal(); + size_t size = lval->Length(); + for ( size_t i = 0; i < size; i++ ) + BuildJSON(writer, lval->Idx(i).get(), only_loggable, re); - writer.EndArray(); - break; - } + writer.EndArray(); + break; + } case TYPE_VECTOR: - { - writer.StartArray(); + { + writer.StartArray(); - auto* vval = val->AsVectorVal(); - size_t size = vval->SizeVal()->AsCount(); - for ( size_t i = 0; i < size; i++ ) - BuildJSON(writer, vval->ValAt(i).get(), only_loggable, re); + auto* vval = val->AsVectorVal(); + size_t size = vval->SizeVal()->AsCount(); + for ( size_t i = 0; i < size; i++ ) + BuildJSON(writer, vval->ValAt(i).get(), only_loggable, re); - writer.EndArray(); - break; - } + writer.EndArray(); + break; + } case TYPE_OPAQUE: - { - writer.StartObject(); + { + writer.StartObject(); - writer.Key("opaque_type"); - auto* oval = val->AsOpaqueVal(); - writer.String(OpaqueMgr::mgr()->TypeID(oval)); + writer.Key("opaque_type"); + auto* oval = val->AsOpaqueVal(); + writer.String(OpaqueMgr::mgr()->TypeID(oval)); - writer.EndObject(); - break; - } + writer.EndObject(); + break; + } default: writer.Null(); @@ -1369,23 +1369,23 @@ static void find_nested_record_types(const TypePtr& t, std::set* fo switch ( t->Tag() ) { case TYPE_RECORD: - { - auto rt = t->AsRecordType(); - found->emplace(rt); + { + auto rt = t->AsRecordType(); + found->emplace(rt); - for ( auto i = 0; i < rt->NumFields(); ++i ) - find_nested_record_types(rt->FieldDecl(i)->type, found); - } + for ( auto i = 0; i < rt->NumFields(); ++i ) + find_nested_record_types(rt->FieldDecl(i)->type, found); + } return; case TYPE_TABLE: find_nested_record_types(t->AsTableType()->GetIndices(), found); find_nested_record_types(t->AsTableType()->Yield(), found); return; case TYPE_LIST: - { - for ( const auto& type : t->AsTypeList()->GetTypes() ) - find_nested_record_types(type, found); - } + { + for ( const auto& type : t->AsTypeList()->GetTypes() ) + find_nested_record_types(type, found); + } return; case TYPE_FUNC: find_nested_record_types(t->AsFuncType()->Params(), found); @@ -2145,63 +2145,63 @@ void TableVal::SendToStore(const Val* index, const TableEntryVal* new_entry_val, { case ELEMENT_NEW: case ELEMENT_CHANGED: - { + { #ifndef __clang__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif - broker::optional expiry; + broker::optional expiry; #ifndef __clang__ #pragma GCC diagnostic pop #endif - auto expire_time = GetExpireTime(); - if ( expire_time == 0 ) - // Entry is set to immediately expire. Let's not forward it. - break; - - if ( expire_time > 0 ) - { - if ( attrs->Find(detail::ATTR_EXPIRE_CREATE) ) - { - // for create expiry, we have to substract the already elapsed time from - // the expiry. - auto e = expire_time - - (run_state::network_time - new_entry_val->ExpireAccessTime()); - if ( e <= 0 ) - // element already expired? Let's not insert it. - break; - - expiry = Broker::detail::convert_expiry(e); - } - else - expiry = Broker::detail::convert_expiry(expire_time); - } - - if ( table_type->IsSet() ) - handle->store.put(std::move(*broker_index), broker::data(), expiry); - else - { - if ( ! new_entry_val ) - { - emit_builtin_error( - "did not receive new value for Broker datastore send operation"); - return; - } - - auto new_value = new_entry_val->GetVal().get(); - auto broker_val = Broker::detail::val_to_data(new_value); - if ( ! broker_val ) - { - emit_builtin_error("invalid Broker data conversation for table value"); - return; - } - - handle->store.put(std::move(*broker_index), std::move(*broker_val), expiry); - } + auto expire_time = GetExpireTime(); + if ( expire_time == 0 ) + // Entry is set to immediately expire. Let's not forward it. break; + + if ( expire_time > 0 ) + { + if ( attrs->Find(detail::ATTR_EXPIRE_CREATE) ) + { + // for create expiry, we have to substract the already elapsed time from + // the expiry. + auto e = expire_time - + (run_state::network_time - new_entry_val->ExpireAccessTime()); + if ( e <= 0 ) + // element already expired? Let's not insert it. + break; + + expiry = Broker::detail::convert_expiry(e); + } + else + expiry = Broker::detail::convert_expiry(expire_time); } + if ( table_type->IsSet() ) + handle->store.put(std::move(*broker_index), broker::data(), expiry); + else + { + if ( ! new_entry_val ) + { + emit_builtin_error( + "did not receive new value for Broker datastore send operation"); + return; + } + + auto new_value = new_entry_val->GetVal().get(); + auto broker_val = Broker::detail::val_to_data(new_value); + if ( ! broker_val ) + { + emit_builtin_error("invalid Broker data conversation for table value"); + return; + } + + handle->store.put(std::move(*broker_index), std::move(*broker_val), expiry); + } + break; + } + case ELEMENT_REMOVED: handle->store.erase(std::move(*broker_index)); break; diff --git a/src/Var.cc b/src/Var.cc index e0d7f7c4c5..4067f17e4c 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -223,19 +223,19 @@ static void make_var(const IDPtr& id, TypePtr t, InitClass c, ExprPtr init, switch ( init->Tag() ) { case EXPR_TABLE_CONSTRUCTOR: - { - auto* ctor = static_cast(init.get()); - if ( ctor->GetAttrs() ) - id->AddAttrs(ctor->GetAttrs()); - } + { + auto* ctor = static_cast(init.get()); + if ( ctor->GetAttrs() ) + id->AddAttrs(ctor->GetAttrs()); + } break; case EXPR_SET_CONSTRUCTOR: - { - auto* ctor = static_cast(init.get()); - if ( ctor->GetAttrs() ) - id->AddAttrs(ctor->GetAttrs()); - } + { + auto* ctor = static_cast(init.get()); + if ( ctor->GetAttrs() ) + id->AddAttrs(ctor->GetAttrs()); + } break; default: diff --git a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc index 34f3d0a77d..1e4d6d9278 100644 --- a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc +++ b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc @@ -256,55 +256,55 @@ bool BitTorrentTracker_Analyzer::ParseRequest(char* line) switch ( req_state ) { case detail::BTT_REQ_GET: + { + regmatch_t match[1]; + if ( regexec(&r_get, line, 1, match, 0) ) { - regmatch_t match[1]; - if ( regexec(&r_get, line, 1, match, 0) ) + ProtocolViolation("BitTorrentTracker: invalid HTTP GET"); + stop_orig = true; + return false; + } + + regmatch_t match_end[1]; + if ( ! regexec(&r_get_end, line, 1, match_end, 0) ) + { + if ( match_end[0].rm_so <= match[0].rm_eo ) { ProtocolViolation("BitTorrentTracker: invalid HTTP GET"); stop_orig = true; return false; } - regmatch_t match_end[1]; - if ( ! regexec(&r_get_end, line, 1, match_end, 0) ) - { - if ( match_end[0].rm_so <= match[0].rm_eo ) - { - ProtocolViolation("BitTorrentTracker: invalid HTTP GET"); - stop_orig = true; - return false; - } - - keep_alive = (line[match_end[0].rm_eo - 1] == '1'); - line[match_end[0].rm_so] = 0; - } - - RequestGet(&line[match[0].rm_eo]); - - req_state = detail::BTT_REQ_HEADER; + keep_alive = (line[match_end[0].rm_eo - 1] == '1'); + line[match_end[0].rm_so] = 0; } + + RequestGet(&line[match[0].rm_eo]); + + req_state = detail::BTT_REQ_HEADER; + } break; case detail::BTT_REQ_HEADER: + { + if ( ! *line ) { - if ( ! *line ) - { - EmitRequest(); - req_state = detail::BTT_REQ_DONE; - break; - } - - regmatch_t match[1]; - if ( regexec(&r_hdr, line, 1, match, 0) ) - { - ProtocolViolation("BitTorrentTracker: invalid HTTP request header"); - stop_orig = true; - return false; - } - - *strchr(line, ':') = 0; // this cannot fail - see regex_hdr - RequestHeader(line, &line[match[0].rm_eo]); + EmitRequest(); + req_state = detail::BTT_REQ_DONE; + break; } + + regmatch_t match[1]; + if ( regexec(&r_hdr, line, 1, match, 0) ) + { + ProtocolViolation("BitTorrentTracker: invalid HTTP request header"); + stop_orig = true; + return false; + } + + *strchr(line, ':') = 0; // this cannot fail - see regex_hdr + RequestHeader(line, &line[match[0].rm_eo]); + } break; case detail::BTT_REQ_DONE: @@ -356,27 +356,27 @@ bool BitTorrentTracker_Analyzer::ParseResponse(char* line) switch ( res_state ) { case detail::BTT_RES_STATUS: + { + if ( res_allow_blank_line && ! *line ) { - if ( res_allow_blank_line && ! *line ) - { - // There may be an empty line after the bencoded - // directory, if this is a keep-alive connection. - // Ignore it. - res_allow_blank_line = false; - break; - } - - regmatch_t match[1]; - if ( regexec(&r_stat, line, 1, match, 0) ) - { - ProtocolViolation("BitTorrentTracker: invalid HTTP status"); - stop_resp = true; - return false; - } - - ResponseStatus(&line[match[0].rm_eo]); - res_state = detail::BTT_RES_HEADER; + // There may be an empty line after the bencoded + // directory, if this is a keep-alive connection. + // Ignore it. + res_allow_blank_line = false; + break; } + + regmatch_t match[1]; + if ( regexec(&r_stat, line, 1, match, 0) ) + { + ProtocolViolation("BitTorrentTracker: invalid HTTP status"); + stop_resp = true; + return false; + } + + ResponseStatus(&line[match[0].rm_eo]); + res_state = detail::BTT_RES_HEADER; + } break; case detail::BTT_RES_HEADER: @@ -523,127 +523,122 @@ int BitTorrentTracker_Analyzer::ResponseParseBenc(void) switch ( benc_state ) { case detail::BENC_STATE_EMPTY: + { + switch ( res_buf_pos[0] ) { - switch ( res_buf_pos[0] ) - { - case 'd': - switch ( benc_stack.size() ) - { - case 0: - break; - case 1: - benc_raw = res_buf_pos; - benc_raw_type = detail::BENC_TYPE_DIR; - /* fall through */ - default: - VIOLATION_IF(benc_stack.back() == 'd' && - ! (benc_count.back() % 2), - "BitTorrentTracker: directory key is not a string " - "but a directory") - ++benc_raw_len; - } - - benc_stack.push_back('d'); - benc_count.push_back(0); - break; - - case 'l': - switch ( benc_stack.size() ) - { - case 0: - VIOLATION_IF(1, "BitTorrentTracker: not a bencoded directory " - "(first char: l)") - /* fall through */ - - case 1: - benc_raw = res_buf_pos; - benc_raw_type = detail::BENC_TYPE_LIST; - /* fall through */ - - default: - VIOLATION_IF(benc_stack.back() == 'd' && - ! (benc_count.back() % 2), - "BitTorrentTracker: directory key is not a string " - "but a list") - ++benc_raw_len; - } - - benc_stack.push_back('l'); - benc_count.push_back(0); - break; - - case 'i': - VIOLATION_IF( - ! benc_stack.size(), - "BitTorrentTracker: not a bencoded directory (first char: i)") - VIOLATION_IF( - benc_stack.back() == 'd' && ! (benc_count.back() % 2), - "BitTorrentTracker: directory key is not a string but an int") - - if ( benc_raw_type != detail::BENC_TYPE_NONE ) + case 'd': + switch ( benc_stack.size() ) + { + case 0: + break; + case 1: + benc_raw = res_buf_pos; + benc_raw_type = detail::BENC_TYPE_DIR; + /* fall through */ + default: + VIOLATION_IF(benc_stack.back() == 'd' && ! (benc_count.back() % 2), + "BitTorrentTracker: directory key is not a string " + "but a directory") ++benc_raw_len; + } - benc_state = detail::BENC_STATE_INT1; - break; + benc_stack.push_back('d'); + benc_count.push_back(0); + break; - case 'e': - VIOLATION_IF( - ! benc_stack.size(), - "BitTorrentTracker: not a bencoded directory (first char: e)") - VIOLATION_IF(benc_stack.back() == 'd' && benc_count.back() % 2, - "BitTorrentTracker: directory has an odd count of members") + case 'l': + switch ( benc_stack.size() ) + { + case 0: + VIOLATION_IF(1, "BitTorrentTracker: not a bencoded directory " + "(first char: l)") + /* fall through */ - if ( benc_raw_type != detail::BENC_TYPE_NONE ) + case 1: + benc_raw = res_buf_pos; + benc_raw_type = detail::BENC_TYPE_LIST; + /* fall through */ + + default: + VIOLATION_IF(benc_stack.back() == 'd' && ! (benc_count.back() % 2), + "BitTorrentTracker: directory key is not a string " + "but a list") ++benc_raw_len; + } - if ( benc_stack.size() == 2 ) - { // coming back to level 1 - ResponseBenc(benc_key_len, benc_key, benc_raw_type, benc_raw_len, - benc_raw); - benc_key = nullptr; - benc_key_len = 0; - benc_raw = nullptr; - benc_raw_len = 0; - benc_raw_type = detail::BENC_TYPE_NONE; - } + benc_stack.push_back('l'); + benc_count.push_back(0); + break; - benc_stack.pop_back(); - benc_count.pop_back(); + case 'i': + VIOLATION_IF(! benc_stack.size(), + "BitTorrentTracker: not a bencoded directory (first char: i)") + VIOLATION_IF(benc_stack.back() == 'd' && ! (benc_count.back() % 2), + "BitTorrentTracker: directory key is not a string but an int") - if ( benc_stack.size() ) - INC_COUNT - else - { // benc parsing successful - ++res_buf_pos; - return 0; - } - break; + if ( benc_raw_type != detail::BENC_TYPE_NONE ) + ++benc_raw_len; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - VIOLATION_IF( - ! benc_stack.size(), - "BitTorrentTracker: not a bencoded directory (first char: [0-9])") + benc_state = detail::BENC_STATE_INT1; + break; - if ( benc_raw_type != detail::BENC_TYPE_NONE ) - ++benc_raw_len; + case 'e': + VIOLATION_IF(! benc_stack.size(), + "BitTorrentTracker: not a bencoded directory (first char: e)") + VIOLATION_IF(benc_stack.back() == 'd' && benc_count.back() % 2, + "BitTorrentTracker: directory has an odd count of members") - benc_strlen = res_buf_pos; - benc_state = detail::BENC_STATE_STR1; - break; + if ( benc_raw_type != detail::BENC_TYPE_NONE ) + ++benc_raw_len; - default: - VIOLATION_IF(1, "BitTorrentTracker: no valid bencoding") - } + if ( benc_stack.size() == 2 ) + { // coming back to level 1 + ResponseBenc(benc_key_len, benc_key, benc_raw_type, benc_raw_len, + benc_raw); + benc_key = nullptr; + benc_key_len = 0; + benc_raw = nullptr; + benc_raw_len = 0; + benc_raw_type = detail::BENC_TYPE_NONE; + } + + benc_stack.pop_back(); + benc_count.pop_back(); + + if ( benc_stack.size() ) + INC_COUNT + else + { // benc parsing successful + ++res_buf_pos; + return 0; + } + break; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + VIOLATION_IF( + ! benc_stack.size(), + "BitTorrentTracker: not a bencoded directory (first char: [0-9])") + + if ( benc_raw_type != detail::BENC_TYPE_NONE ) + ++benc_raw_len; + + benc_strlen = res_buf_pos; + benc_state = detail::BENC_STATE_STR1; + break; + + default: + VIOLATION_IF(1, "BitTorrentTracker: no valid bencoding") } + } break; case detail::BENC_STATE_INT1: diff --git a/src/analyzer/protocol/dns/DNS.cc b/src/analyzer/protocol/dns/DNS.cc index 952e470b07..e34d0aa495 100644 --- a/src/analyzer/protocol/dns/DNS.cc +++ b/src/analyzer/protocol/dns/DNS.cc @@ -698,190 +698,188 @@ bool DNS_Interpreter::ParseRR_EDNS(detail::DNS_MsgInfo* msg, const u_char*& data switch ( option_code ) { case detail::TYPE_ECS: + { + // must be 4 bytes + variable number of octets for address + if ( option_len <= 4 ) { - // must be 4 bytes + variable number of octets for address - if ( option_len <= 4 ) - { - analyzer->Weird("EDNS_ECS_invalid_option_len"); - data += option_len; - break; - } - - detail::EDNS_ECS opt{}; - uint16_t ecs_family = ExtractShort(data, option_len); - uint16_t source_scope = ExtractShort(data, option_len); - opt.ecs_src_pfx_len = (source_scope >> 8) & 0xff; - opt.ecs_scp_pfx_len = source_scope & 0xff; - - // ADDRESS, variable number of octets, contains either an IPv4 or - // IPv6 address, depending on FAMILY, which MUST be truncated to the - // number of bits indicated by the SOURCE PREFIX-LENGTH field, - // padding with 0 bits to pad to the end of the last octet needed. - if ( ecs_family == L3_IPV4 ) - { - if ( opt.ecs_src_pfx_len > 32 ) - { - analyzer->Weird("EDNS_ECS_invalid_addr_v4_prefix", - util::fmt("%" PRIu16 " bits", opt.ecs_src_pfx_len)); - data += option_len; - break; - } - - if ( opt.ecs_src_pfx_len > option_len * 8 ) - { - analyzer->Weird("EDNS_ECS_invalid_addr_v4", - util::fmt("need %" PRIu16 " bits, have %d bits", - opt.ecs_src_pfx_len, option_len * 8)); - data += option_len; - break; - } - - opt.ecs_family = make_intrusive("v4"); - uint32_t addr = 0; - uint16_t shift_factor = 3; - int bits_left = opt.ecs_src_pfx_len; - - while ( bits_left > 0 ) - { - addr |= data[0] << (shift_factor * 8); - data++; - shift_factor--; - option_len--; - bits_left -= 8; - } - - addr = htonl(addr); - opt.ecs_addr = make_intrusive(addr); - } - else if ( ecs_family == L3_IPV6 ) - { - if ( opt.ecs_src_pfx_len > 128 ) - { - analyzer->Weird("EDNS_ECS_invalid_addr_v6_prefix", - util::fmt("%" PRIu16 " bits", opt.ecs_src_pfx_len)); - data += option_len; - break; - } - - if ( opt.ecs_src_pfx_len > option_len * 8 ) - { - analyzer->Weird("EDNS_ECS_invalid_addr_v6", - util::fmt("need %" PRIu16 " bits, have %d bits", - opt.ecs_src_pfx_len, option_len * 8)); - data += option_len; - break; - } - - opt.ecs_family = make_intrusive("v6"); - uint32_t addr[4] = {0}; - uint16_t shift_factor = 15; - int bits_left = opt.ecs_src_pfx_len; - int i = 0; - - while ( bits_left > 0 ) - { - addr[i / 4] |= data[0] << ((shift_factor % 4) * 8); - data++; - i++; - shift_factor--; - option_len--; - bits_left -= 8; - } - - for ( uint8_t i = 0; i < 4; i++ ) - { - addr[i] = htonl(addr[i]); - } - opt.ecs_addr = make_intrusive(addr); - } - else - { - // non ipv4/ipv6 family address - data += option_len; - break; - } - - analyzer->EnqueueConnEvent(dns_EDNS_ecs, analyzer->ConnVal(), - msg->BuildHdrVal(), msg->BuildEDNS_ECS_Val(&opt)); - data += option_len; - break; - } // END EDNS ECS - - case TYPE_TCP_KA: - { - EDNS_TCP_KEEPALIVE edns_tcp_keepalive{.keepalive_timeout_omitted = true, - .keepalive_timeout = 0}; - if ( option_len == 0 || option_len == 2 ) - { - // 0 bytes is permitted by RFC 7828, showing that the timeout value is - // omitted. - if ( option_len == 2 ) - { - edns_tcp_keepalive.keepalive_timeout = ExtractShort(data, option_len); - edns_tcp_keepalive.keepalive_timeout_omitted = false; - } - - if ( analyzer->Conn()->ConnTransport() == TRANSPORT_UDP ) - { - /* - * Based on RFC 7828 (3.2.1/3.2.2), clients and servers MUST NOT - * negotiate TCP Keepalive timeout in DNS-over-UDP. - */ - analyzer->Weird("EDNS_TCP_Keepalive_In_UDP"); - } - - analyzer->EnqueueConnEvent(dns_EDNS_tcp_keepalive, analyzer->ConnVal(), - msg->BuildHdrVal(), - msg->BuildEDNS_TCP_KA_Val(&edns_tcp_keepalive)); - } - else - { - // error. MUST BE 0 or 2 bytes. skip - data += option_len; - } - break; - } // END EDNS TCP KEEPALIVE - - case TYPE_COOKIE: - { - EDNS_COOKIE cookie{}; - if ( option_len != 8 && ! (option_len >= 16 && option_len <= 40) ) - { - /* - * option length for DNS Cookie must be 8 bytes (with client cookie only) - * OR - * between 16 bytes to 40 bytes (with an 8 bytes client and an 8 to 32 bytes - * server cookie) - */ - data += option_len; - break; - } - - int client_cookie_len = 8; - int server_cookie_len = option_len - client_cookie_len; - - cookie.client_cookie = - ExtractStream(data, client_cookie_len, client_cookie_len); - cookie.server_cookie = nullptr; - - if ( server_cookie_len >= 8 ) - { - cookie.server_cookie = - ExtractStream(data, server_cookie_len, server_cookie_len); - } - - analyzer->EnqueueConnEvent(dns_EDNS_cookie, analyzer->ConnVal(), - msg->BuildHdrVal(), - msg->BuildEDNS_COOKIE_Val(&cookie)); - - break; - } // END EDNS COOKIE - - default: - { + analyzer->Weird("EDNS_ECS_invalid_option_len"); data += option_len; break; } + + detail::EDNS_ECS opt{}; + uint16_t ecs_family = ExtractShort(data, option_len); + uint16_t source_scope = ExtractShort(data, option_len); + opt.ecs_src_pfx_len = (source_scope >> 8) & 0xff; + opt.ecs_scp_pfx_len = source_scope & 0xff; + + // ADDRESS, variable number of octets, contains either an IPv4 or + // IPv6 address, depending on FAMILY, which MUST be truncated to the + // number of bits indicated by the SOURCE PREFIX-LENGTH field, + // padding with 0 bits to pad to the end of the last octet needed. + if ( ecs_family == L3_IPV4 ) + { + if ( opt.ecs_src_pfx_len > 32 ) + { + analyzer->Weird("EDNS_ECS_invalid_addr_v4_prefix", + util::fmt("%" PRIu16 " bits", opt.ecs_src_pfx_len)); + data += option_len; + break; + } + + if ( opt.ecs_src_pfx_len > option_len * 8 ) + { + analyzer->Weird("EDNS_ECS_invalid_addr_v4", + util::fmt("need %" PRIu16 " bits, have %d bits", + opt.ecs_src_pfx_len, option_len * 8)); + data += option_len; + break; + } + + opt.ecs_family = make_intrusive("v4"); + uint32_t addr = 0; + uint16_t shift_factor = 3; + int bits_left = opt.ecs_src_pfx_len; + + while ( bits_left > 0 ) + { + addr |= data[0] << (shift_factor * 8); + data++; + shift_factor--; + option_len--; + bits_left -= 8; + } + + addr = htonl(addr); + opt.ecs_addr = make_intrusive(addr); + } + else if ( ecs_family == L3_IPV6 ) + { + if ( opt.ecs_src_pfx_len > 128 ) + { + analyzer->Weird("EDNS_ECS_invalid_addr_v6_prefix", + util::fmt("%" PRIu16 " bits", opt.ecs_src_pfx_len)); + data += option_len; + break; + } + + if ( opt.ecs_src_pfx_len > option_len * 8 ) + { + analyzer->Weird("EDNS_ECS_invalid_addr_v6", + util::fmt("need %" PRIu16 " bits, have %d bits", + opt.ecs_src_pfx_len, option_len * 8)); + data += option_len; + break; + } + + opt.ecs_family = make_intrusive("v6"); + uint32_t addr[4] = {0}; + uint16_t shift_factor = 15; + int bits_left = opt.ecs_src_pfx_len; + int i = 0; + + while ( bits_left > 0 ) + { + addr[i / 4] |= data[0] << ((shift_factor % 4) * 8); + data++; + i++; + shift_factor--; + option_len--; + bits_left -= 8; + } + + for ( uint8_t i = 0; i < 4; i++ ) + { + addr[i] = htonl(addr[i]); + } + opt.ecs_addr = make_intrusive(addr); + } + else + { + // non ipv4/ipv6 family address + data += option_len; + break; + } + + analyzer->EnqueueConnEvent(dns_EDNS_ecs, analyzer->ConnVal(), msg->BuildHdrVal(), + msg->BuildEDNS_ECS_Val(&opt)); + data += option_len; + break; + } // END EDNS ECS + + case TYPE_TCP_KA: + { + EDNS_TCP_KEEPALIVE edns_tcp_keepalive{.keepalive_timeout_omitted = true, + .keepalive_timeout = 0}; + if ( option_len == 0 || option_len == 2 ) + { + // 0 bytes is permitted by RFC 7828, showing that the timeout value is + // omitted. + if ( option_len == 2 ) + { + edns_tcp_keepalive.keepalive_timeout = ExtractShort(data, option_len); + edns_tcp_keepalive.keepalive_timeout_omitted = false; + } + + if ( analyzer->Conn()->ConnTransport() == TRANSPORT_UDP ) + { + /* + * Based on RFC 7828 (3.2.1/3.2.2), clients and servers MUST NOT + * negotiate TCP Keepalive timeout in DNS-over-UDP. + */ + analyzer->Weird("EDNS_TCP_Keepalive_In_UDP"); + } + + analyzer->EnqueueConnEvent(dns_EDNS_tcp_keepalive, analyzer->ConnVal(), + msg->BuildHdrVal(), + msg->BuildEDNS_TCP_KA_Val(&edns_tcp_keepalive)); + } + else + { + // error. MUST BE 0 or 2 bytes. skip + data += option_len; + } + break; + } // END EDNS TCP KEEPALIVE + + case TYPE_COOKIE: + { + EDNS_COOKIE cookie{}; + if ( option_len != 8 && ! (option_len >= 16 && option_len <= 40) ) + { + /* + * option length for DNS Cookie must be 8 bytes (with client cookie only) + * OR + * between 16 bytes to 40 bytes (with an 8 bytes client and an 8 to 32 bytes + * server cookie) + */ + data += option_len; + break; + } + + int client_cookie_len = 8; + int server_cookie_len = option_len - client_cookie_len; + + cookie.client_cookie = ExtractStream(data, client_cookie_len, client_cookie_len); + cookie.server_cookie = nullptr; + + if ( server_cookie_len >= 8 ) + { + cookie.server_cookie = + ExtractStream(data, server_cookie_len, server_cookie_len); + } + + analyzer->EnqueueConnEvent(dns_EDNS_cookie, analyzer->ConnVal(), msg->BuildHdrVal(), + msg->BuildEDNS_COOKIE_Val(&cookie)); + + break; + } // END EDNS COOKIE + + default: + { + data += option_len; + break; + } } } diff --git a/src/analyzer/protocol/http/HTTP.cc b/src/analyzer/protocol/http/HTTP.cc index 02ab9b05c6..ff52cb5dab 100644 --- a/src/analyzer/protocol/http/HTTP.cc +++ b/src/analyzer/protocol/http/HTTP.cc @@ -925,52 +925,51 @@ void HTTP_Analyzer::DeliverStream(int len, const u_char* data, bool is_orig) switch ( request_state ) { case EXPECT_REQUEST_LINE: + { + int res = HTTP_RequestLine(line, end_of_line); + + if ( res < 0 ) + return; + + else if ( res > 0 ) { - int res = HTTP_RequestLine(line, end_of_line); + ++num_requests; - if ( res < 0 ) - return; + if ( ! keep_alive && num_requests > 1 ) + Weird("unexpected_multiple_HTTP_requests"); - else if ( res > 0 ) - { - ++num_requests; - - if ( ! keep_alive && num_requests > 1 ) - Weird("unexpected_multiple_HTTP_requests"); - - request_state = EXPECT_REQUEST_MESSAGE; - request_ongoing = 1; - unanswered_requests.push(request_method); - HTTP_Request(); - InitHTTPMessage(content_line, request_message, is_orig, HTTP_BODY_MAYBE, - len); - } + request_state = EXPECT_REQUEST_MESSAGE; + request_ongoing = 1; + unanswered_requests.push(request_method); + HTTP_Request(); + InitHTTPMessage(content_line, request_message, is_orig, HTTP_BODY_MAYBE, len); + } + else + { + if ( ! RequestExpected() ) + HTTP_Event("crud_trailing_HTTP_request", + analyzer::mime::to_string_val(line, end_of_line)); else { - if ( ! RequestExpected() ) - HTTP_Event("crud_trailing_HTTP_request", - analyzer::mime::to_string_val(line, end_of_line)); + // We do see HTTP requests with a + // trailing EOL that's not accounted + // for by the content-length. This + // will lead to a call to this method + // with len==0 while we are expecting + // a new request. Since HTTP servers + // handle such requests gracefully, + // we should do so as well. + if ( len == 0 ) + Weird("empty_http_request"); else { - // We do see HTTP requests with a - // trailing EOL that's not accounted - // for by the content-length. This - // will lead to a call to this method - // with len==0 while we are expecting - // a new request. Since HTTP servers - // handle such requests gracefully, - // we should do so as well. - if ( len == 0 ) - Weird("empty_http_request"); - else - { - ProtocolViolation("not a http request line"); - request_state = EXPECT_REQUEST_NOTHING; - } + ProtocolViolation("not a http request line"); + request_state = EXPECT_REQUEST_NOTHING; } } } + } break; case EXPECT_REQUEST_MESSAGE: diff --git a/src/analyzer/protocol/irc/IRC.cc b/src/analyzer/protocol/irc/IRC.cc index 1d3f0db1ee..fbade0eaf0 100644 --- a/src/analyzer/protocol/irc/IRC.cc +++ b/src/analyzer/protocol/irc/IRC.cc @@ -279,7 +279,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) make_intrusive(type.c_str()), make_intrusive(channel.c_str()), std::move(set)); } - break; + break; // Count of users and services on this server. case 255: @@ -456,38 +456,38 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) // RPL_TOPIC reply. case 332: - { - if ( ! irc_channel_topic ) - break; - - vector parts = SplitWords(params, ' '); - if ( parts.size() < 4 ) - { - Weird("irc_invalid_topic_reply"); - return; - } - - unsigned int pos = params.find(':'); - if ( pos < params.size() ) - { - string topic = params.substr(pos + 1); - const char* t = topic.c_str(); - - if ( *t == ':' ) - ++t; - - EnqueueConnEvent(irc_channel_topic, ConnVal(), val_mgr->Bool(orig), - make_intrusive(parts[1].c_str()), - make_intrusive(t)); - } - else - { - Weird("irc_invalid_topic_reply"); - return; - } - } + { + if ( ! irc_channel_topic ) break; + vector parts = SplitWords(params, ' '); + if ( parts.size() < 4 ) + { + Weird("irc_invalid_topic_reply"); + return; + } + + unsigned int pos = params.find(':'); + if ( pos < params.size() ) + { + string topic = params.substr(pos + 1); + const char* t = topic.c_str(); + + if ( *t == ':' ) + ++t; + + EnqueueConnEvent(irc_channel_topic, ConnVal(), val_mgr->Bool(orig), + make_intrusive(parts[1].c_str()), + make_intrusive(t)); + } + else + { + Weird("irc_invalid_topic_reply"); + return; + } + } + break; + // WHO reply line. case 352: { diff --git a/src/analyzer/protocol/login/NVT.cc b/src/analyzer/protocol/login/NVT.cc index fc675e2b40..894aced4da 100644 --- a/src/analyzer/protocol/login/NVT.cc +++ b/src/analyzer/protocol/login/NVT.cc @@ -208,20 +208,19 @@ void TelnetAuthenticateOption::RecvSubOption(u_char* data, int len) switch ( data[0] ) { case HERE_IS_AUTHENTICATION: + { + TelnetAuthenticateOption* peer = (TelnetAuthenticateOption*)endp->FindPeerOption(code); + + if ( ! peer ) { - TelnetAuthenticateOption* peer = - (TelnetAuthenticateOption*)endp->FindPeerOption(code); - - if ( ! peer ) - { - reporter->AnalyzerError( - endp, "option peer missing in TelnetAuthenticateOption::RecvSubOption"); - return; - } - - if ( ! peer->DidRequestAuthentication() ) - InconsistentOption(0); + reporter->AnalyzerError( + endp, "option peer missing in TelnetAuthenticateOption::RecvSubOption"); + return; } + + if ( ! peer->DidRequestAuthentication() ) + InconsistentOption(0); + } break; case SEND_ME_AUTHENTICATION: @@ -247,11 +246,11 @@ void TelnetAuthenticateOption::RecvSubOption(u_char* data, int len) break; case AUTHENTICATION_NAME: - { - char* auth_name = new char[len]; - util::safe_strncpy(auth_name, (char*)data + 1, len); - endp->SetAuthName(auth_name); - } + { + char* auth_name = new char[len]; + util::safe_strncpy(auth_name, (char*)data + 1, len); + endp->SetAuthName(auth_name); + } break; default: diff --git a/src/analyzer/protocol/pop3/POP3.cc b/src/analyzer/protocol/pop3/POP3.cc index 9cffe3b2e1..4054c3ffb2 100644 --- a/src/analyzer/protocol/pop3/POP3.cc +++ b/src/analyzer/protocol/pop3/POP3.cc @@ -155,57 +155,57 @@ void POP3_Analyzer::ProcessRequest(int length, const char* line) break; case detail::AUTH_PLAIN: + { + // Format: "authorization identityauthentication + // identitypassword" + char* str = (char*)decoded->Bytes(); + int len = decoded->Len(); + char* end = str + len; + char* s; + char* e; + + for ( s = str; s < end && *s; ++s ) + ; + ++s; + + for ( e = s; e < end && *e; ++e ) + ; + + if ( e >= end ) { - // Format: "authorization identityauthentication - // identitypassword" - char* str = (char*)decoded->Bytes(); - int len = decoded->Len(); - char* end = str + len; - char* s; - char* e; - - for ( s = str; s < end && *s; ++s ) - ; - ++s; - - for ( e = s; e < end && *e; ++e ) - ; - - if ( e >= end ) - { - Weird("pop3_malformed_auth_plain"); - delete decoded; - return; - } - - user = s; - s = e + 1; - - if ( s >= end ) - { - Weird("pop3_malformed_auth_plain"); - delete decoded; - return; - } - - password.assign(s, len - (s - str)); - - break; + Weird("pop3_malformed_auth_plain"); + delete decoded; + return; } + user = s; + s = e + 1; + + if ( s >= end ) + { + Weird("pop3_malformed_auth_plain"); + delete decoded; + return; + } + + password.assign(s, len - (s - str)); + + break; + } + case detail::AUTH_CRAM_MD5: - { // Format: "userpassword-hash" - const char* s; - const char* str = (char*)decoded->CheckString(); + { // Format: "userpassword-hash" + const char* s; + const char* str = (char*)decoded->CheckString(); - for ( s = str; *s && *s != '\t' && *s != ' '; ++s ) - ; + for ( s = str; *s && *s != '\t' && *s != ' '; ++s ) + ; - user = std::string(str, s); - password = ""; + user = std::string(str, s); + password = ""; - break; - } + break; + } case detail::AUTH: break; @@ -694,16 +694,16 @@ void POP3_Analyzer::ProcessReply(int length, const char* line) case detail::TOP: case detail::RETR: - { - int data_len = end_of_line - line; - if ( ! mail ) - // ProcessReply is only called if orig == false - BeginData(false); - ProcessData(data_len, line); - if ( requestForMultiLine == true ) - multiLine = true; - break; - } + { + int data_len = end_of_line - line; + if ( ! mail ) + // ProcessReply is only called if orig == false + BeginData(false); + ProcessData(data_len, line); + if ( requestForMultiLine == true ) + multiLine = true; + break; + } case detail::CAPA: ProtocolConfirmation(); diff --git a/src/analyzer/protocol/rpc/Portmap.cc b/src/analyzer/protocol/rpc/Portmap.cc index eee978812d..94b9f4e603 100644 --- a/src/analyzer/protocol/rpc/Portmap.cc +++ b/src/analyzer/protocol/rpc/Portmap.cc @@ -32,42 +32,42 @@ bool PortmapperInterp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n break; case PMAPPROC_SET: - { - auto m = ExtractMapping(buf, n); - if ( ! m ) - return false; - c->AddVal(std::move(m)); - } + { + auto m = ExtractMapping(buf, n); + if ( ! m ) + return false; + c->AddVal(std::move(m)); + } break; case PMAPPROC_UNSET: - { - auto m = ExtractMapping(buf, n); - if ( ! m ) - return false; - c->AddVal(std::move(m)); - } + { + auto m = ExtractMapping(buf, n); + if ( ! m ) + return false; + c->AddVal(std::move(m)); + } break; case PMAPPROC_GETPORT: - { - auto pr = ExtractPortRequest(buf, n); - if ( ! pr ) - return false; - c->AddVal(std::move(pr)); - } + { + auto pr = ExtractPortRequest(buf, n); + if ( ! pr ) + return false; + c->AddVal(std::move(pr)); + } break; case PMAPPROC_DUMP: break; case PMAPPROC_CALLIT: - { - auto call_it = ExtractCallItRequest(buf, n); - if ( ! call_it ) - return false; - c->AddVal(std::move(call_it)); - } + { + auto call_it = ExtractCallItRequest(buf, n); + if ( ! call_it ) + return false; + c->AddVal(std::move(call_it)); + } break; default: diff --git a/src/analyzer/protocol/rpc/RPC.cc b/src/analyzer/protocol/rpc/RPC.cc index f06d996313..f8bef3a887 100644 --- a/src/analyzer/protocol/rpc/RPC.cc +++ b/src/analyzer/protocol/rpc/RPC.cc @@ -636,75 +636,73 @@ void Contents_RPC::DeliverStream(int len, const u_char* data, bool orig) // no break. fall through case WAIT_FOR_MARKER: + { + bool got_marker = marker_buf.ConsumeChunk(data, len); + + if ( got_marker ) { - bool got_marker = marker_buf.ConsumeChunk(data, len); + const u_char* dummy_p = marker_buf.GetBuf(); + int dummy_len = (int)marker_buf.GetFill(); - if ( got_marker ) + // have full marker + marker = extract_XDR_uint32(dummy_p, dummy_len); + marker_buf.Init(4, 4); + + if ( ! dummy_p ) { - const u_char* dummy_p = marker_buf.GetBuf(); - int dummy_len = (int)marker_buf.GetFill(); - - // have full marker - marker = extract_XDR_uint32(dummy_p, dummy_len); - marker_buf.Init(4, 4); - - if ( ! dummy_p ) - { - reporter->AnalyzerError(this, - "inconsistent RPC record marker extraction"); - return; - } - - last_frag = (marker & 0x80000000) != 0; - marker &= 0x7fffffff; - // printf("%.6f %d marker= %u <> last_frag= %d <> expected=%llu <> - // processed= %llu <> len = %d\n", run_state::network_time, IsOrig(), - // marker, - // last_frag, msg_buf.GetExpected(), msg_buf.GetProcessed(), len); - - if ( ! msg_buf.AddToExpected(marker) ) - Conn()->Weird("RPC_message_too_long", - util::fmt("%" PRId64, msg_buf.GetExpected())); - - if ( last_frag ) - state = WAIT_FOR_LAST_DATA; - else - state = WAIT_FOR_DATA; + reporter->AnalyzerError(this, "inconsistent RPC record marker extraction"); + return; } + + last_frag = (marker & 0x80000000) != 0; + marker &= 0x7fffffff; + // printf("%.6f %d marker= %u <> last_frag= %d <> expected=%llu <> + // processed= %llu <> len = %d\n", run_state::network_time, IsOrig(), + // marker, + // last_frag, msg_buf.GetExpected(), msg_buf.GetProcessed(), len); + + if ( ! msg_buf.AddToExpected(marker) ) + Conn()->Weird("RPC_message_too_long", + util::fmt("%" PRId64, msg_buf.GetExpected())); + + if ( last_frag ) + state = WAIT_FOR_LAST_DATA; + else + state = WAIT_FOR_DATA; } + } // Else remain in state. Haven't got the full 4 bytes // for the marker yet. break; case WAIT_FOR_DATA: case WAIT_FOR_LAST_DATA: + { + bool got_all_data = msg_buf.ConsumeChunk(data, len); + + if ( got_all_data ) { - bool got_all_data = msg_buf.ConsumeChunk(data, len); - - if ( got_all_data ) + // Got all the data we expected. Now let's + // see whether there is another fragment + // coming or whether we just finished the + // last fragment. + if ( state == WAIT_FOR_LAST_DATA ) { - // Got all the data we expected. Now let's - // see whether there is another fragment - // coming or whether we just finished the - // last fragment. - if ( state == WAIT_FOR_LAST_DATA ) - { - const u_char* dummy_p = msg_buf.GetBuf(); - int dummy_len = (int)msg_buf.GetFill(); + const u_char* dummy_p = msg_buf.GetBuf(); + int dummy_len = (int)msg_buf.GetFill(); - if ( ! interp->DeliverRPC(dummy_p, dummy_len, - (int)msg_buf.GetExpected(), IsOrig(), - start_time, last_time) ) - Conn()->Weird("partial_RPC"); + if ( ! interp->DeliverRPC(dummy_p, dummy_len, (int)msg_buf.GetExpected(), + IsOrig(), start_time, last_time) ) + Conn()->Weird("partial_RPC"); - state = WAIT_FOR_MESSAGE; - } - else - state = WAIT_FOR_MARKER; + state = WAIT_FOR_MESSAGE; } - // Else remain in state. Haven't read all the data - // yet. + else + state = WAIT_FOR_MARKER; } + // Else remain in state. Haven't read all the data + // yet. + } break; } // end switch } // end while diff --git a/src/broker/Data.cc b/src/broker/Data.cc index bf13a6fd96..8045edb6b7 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -134,14 +134,14 @@ struct val_converter case TYPE_STRING: return make_intrusive(a.size(), a.data()); case TYPE_FILE: - { - auto file = File::Get(a.data()); + { + auto file = File::Get(a.data()); - if ( file ) - return make_intrusive(std::move(file)); + if ( file ) + return make_intrusive(std::move(file)); - return nullptr; - } + return nullptr; + } default: return nullptr; } @@ -842,231 +842,231 @@ broker::expected val_to_data(const Val* v) case TYPE_COUNT: return {v->AsCount()}; case TYPE_PORT: - { - auto p = v->AsPortVal(); - return {broker::port(p->Port(), to_broker_port_proto(p->PortType()))}; - } + { + auto p = v->AsPortVal(); + return {broker::port(p->Port(), to_broker_port_proto(p->PortType()))}; + } case TYPE_ADDR: - { - auto a = v->AsAddr(); - in6_addr tmp; - a.CopyIPv6(&tmp); - return {broker::address(reinterpret_cast(&tmp), - broker::address::family::ipv6, - broker::address::byte_order::network)}; - } + { + auto a = v->AsAddr(); + in6_addr tmp; + a.CopyIPv6(&tmp); + return {broker::address(reinterpret_cast(&tmp), + broker::address::family::ipv6, + broker::address::byte_order::network)}; + } break; case TYPE_SUBNET: - { - auto s = v->AsSubNet(); - in6_addr tmp; - s.Prefix().CopyIPv6(&tmp); - auto a = broker::address(reinterpret_cast(&tmp), - broker::address::family::ipv6, - broker::address::byte_order::network); - return {broker::subnet(std::move(a), s.Length())}; - } + { + auto s = v->AsSubNet(); + in6_addr tmp; + s.Prefix().CopyIPv6(&tmp); + auto a = broker::address(reinterpret_cast(&tmp), + broker::address::family::ipv6, + broker::address::byte_order::network); + return {broker::subnet(std::move(a), s.Length())}; + } break; case TYPE_DOUBLE: return {v->AsDouble()}; case TYPE_TIME: - { - auto secs = broker::fractional_seconds{v->AsTime()}; - auto since_epoch = std::chrono::duration_cast(secs); - return {broker::timestamp{since_epoch}}; - } + { + auto secs = broker::fractional_seconds{v->AsTime()}; + auto since_epoch = std::chrono::duration_cast(secs); + return {broker::timestamp{since_epoch}}; + } case TYPE_INTERVAL: - { - auto secs = broker::fractional_seconds{v->AsInterval()}; - return {std::chrono::duration_cast(secs)}; - } + { + auto secs = broker::fractional_seconds{v->AsInterval()}; + return {std::chrono::duration_cast(secs)}; + } case TYPE_ENUM: - { - auto enum_type = v->GetType()->AsEnumType(); - auto enum_name = enum_type->Lookup(v->AsEnum()); - return {broker::enum_value(enum_name ? enum_name : "")}; - } + { + auto enum_type = v->GetType()->AsEnumType(); + auto enum_name = enum_type->Lookup(v->AsEnum()); + return {broker::enum_value(enum_name ? enum_name : "")}; + } case TYPE_STRING: - { - auto s = v->AsString(); - return {string(reinterpret_cast(s->Bytes()), s->Len())}; - } + { + auto s = v->AsString(); + return {string(reinterpret_cast(s->Bytes()), s->Len())}; + } case TYPE_FILE: return {string(v->AsFile()->Name())}; case TYPE_FUNC: + { + const Func* f = v->AsFunc(); + std::string name(f->Name()); + + broker::vector rval; + rval.push_back(name); + + if ( name.find("lambda_<") == 0 ) { - const Func* f = v->AsFunc(); - std::string name(f->Name()); - - broker::vector rval; - rval.push_back(name); - - if ( name.find("lambda_<") == 0 ) + // Only ScriptFuncs have closures. + if ( auto b = dynamic_cast(f) ) { - // Only ScriptFuncs have closures. - if ( auto b = dynamic_cast(f) ) - { - auto bc = b->SerializeClosure(); - if ( ! bc ) - return broker::ec::invalid_data; - - rval.emplace_back(std::move(*bc)); - } - else - { - reporter->InternalWarning("Closure with non-ScriptFunc"); + auto bc = b->SerializeClosure(); + if ( ! bc ) return broker::ec::invalid_data; - } + + rval.emplace_back(std::move(*bc)); + } + else + { + reporter->InternalWarning("Closure with non-ScriptFunc"); + return broker::ec::invalid_data; + } + } + + return {std::move(rval)}; + } + case TYPE_TABLE: + { + auto is_set = v->GetType()->IsSet(); + auto table = v->AsTable(); + auto table_val = v->AsTableVal(); + broker::data rval; + + if ( is_set ) + rval = broker::set(); + else + rval = broker::table(); + + for ( const auto& te : *table ) + { + auto hk = te.GetHashKey(); + auto* entry = te.GetValue(); + + auto vl = table_val->RecreateIndex(*hk); + + broker::vector composite_key; + composite_key.reserve(vl->Length()); + + for ( auto k = 0; k < vl->Length(); ++k ) + { + auto key_part = val_to_data(vl->Idx(k).get()); + + if ( ! key_part ) + return broker::ec::invalid_data; + + composite_key.emplace_back(move(*key_part)); } - return {std::move(rval)}; - } - case TYPE_TABLE: - { - auto is_set = v->GetType()->IsSet(); - auto table = v->AsTable(); - auto table_val = v->AsTableVal(); - broker::data rval; + broker::data key; + + if ( composite_key.size() == 1 ) + key = move(composite_key[0]); + else + key = move(composite_key); if ( is_set ) - rval = broker::set(); + caf::get(rval).emplace(move(key)); else - rval = broker::table(); - - for ( const auto& te : *table ) { - auto hk = te.GetHashKey(); - auto* entry = te.GetValue(); + auto val = val_to_data(entry->GetVal().get()); - auto vl = table_val->RecreateIndex(*hk); + if ( ! val ) + return broker::ec::invalid_data; - broker::vector composite_key; - composite_key.reserve(vl->Length()); - - for ( auto k = 0; k < vl->Length(); ++k ) - { - auto key_part = val_to_data(vl->Idx(k).get()); - - if ( ! key_part ) - return broker::ec::invalid_data; - - composite_key.emplace_back(move(*key_part)); - } - - broker::data key; - - if ( composite_key.size() == 1 ) - key = move(composite_key[0]); - else - key = move(composite_key); - - if ( is_set ) - caf::get(rval).emplace(move(key)); - else - { - auto val = val_to_data(entry->GetVal().get()); - - if ( ! val ) - return broker::ec::invalid_data; - - caf::get(rval).emplace(move(key), move(*val)); - } + caf::get(rval).emplace(move(key), move(*val)); } - - return {std::move(rval)}; } + + return {std::move(rval)}; + } case TYPE_VECTOR: + { + auto vec = v->AsVectorVal(); + broker::vector rval; + rval.reserve(vec->Size()); + + for ( auto i = 0u; i < vec->Size(); ++i ) { - auto vec = v->AsVectorVal(); - broker::vector rval; - rval.reserve(vec->Size()); + auto item_val = vec->ValAt(i); - for ( auto i = 0u; i < vec->Size(); ++i ) - { - auto item_val = vec->ValAt(i); + if ( ! item_val ) + continue; - if ( ! item_val ) - continue; + auto item = val_to_data(item_val.get()); - auto item = val_to_data(item_val.get()); + if ( ! item ) + return broker::ec::invalid_data; - if ( ! item ) - return broker::ec::invalid_data; - - rval.emplace_back(move(*item)); - } - - return {std::move(rval)}; + rval.emplace_back(move(*item)); } + + return {std::move(rval)}; + } case TYPE_LIST: + { + // We don't really support lists on the broker side. + // So we just pretend that it is a vector instead. + auto list = v->AsListVal(); + broker::vector rval; + rval.reserve(list->Length()); + + for ( auto i = 0; i < list->Length(); ++i ) { - // We don't really support lists on the broker side. - // So we just pretend that it is a vector instead. - auto list = v->AsListVal(); - broker::vector rval; - rval.reserve(list->Length()); + const auto& item_val = list->Idx(i); - for ( auto i = 0; i < list->Length(); ++i ) - { - const auto& item_val = list->Idx(i); + if ( ! item_val ) + continue; - if ( ! item_val ) - continue; + auto item = val_to_data(item_val.get()); - auto item = val_to_data(item_val.get()); + if ( ! item ) + return broker::ec::invalid_data; - if ( ! item ) - return broker::ec::invalid_data; - - rval.emplace_back(move(*item)); - } - - return {std::move(rval)}; + rval.emplace_back(move(*item)); } + + return {std::move(rval)}; + } case TYPE_RECORD: + { + auto rec = v->AsRecordVal(); + broker::vector rval; + size_t num_fields = v->GetType()->AsRecordType()->NumFields(); + rval.reserve(num_fields); + + for ( size_t i = 0; i < num_fields; ++i ) { - auto rec = v->AsRecordVal(); - broker::vector rval; - size_t num_fields = v->GetType()->AsRecordType()->NumFields(); - rval.reserve(num_fields); + auto item_val = rec->GetFieldOrDefault(i); - for ( size_t i = 0; i < num_fields; ++i ) + if ( ! item_val ) { - auto item_val = rec->GetFieldOrDefault(i); - - if ( ! item_val ) - { - rval.emplace_back(broker::nil); - continue; - } - - auto item = val_to_data(item_val.get()); - - if ( ! item ) - return broker::ec::invalid_data; - - rval.emplace_back(move(*item)); + rval.emplace_back(broker::nil); + continue; } - return {std::move(rval)}; + auto item = val_to_data(item_val.get()); + + if ( ! item ) + return broker::ec::invalid_data; + + rval.emplace_back(move(*item)); } + + return {std::move(rval)}; + } case TYPE_PATTERN: - { - const RE_Matcher* p = v->AsPattern(); - broker::vector rval = {p->PatternText(), p->AnywherePatternText()}; - return {std::move(rval)}; - } + { + const RE_Matcher* p = v->AsPattern(); + broker::vector rval = {p->PatternText(), p->AnywherePatternText()}; + return {std::move(rval)}; + } case TYPE_OPAQUE: + { + auto c = v->AsOpaqueVal()->Serialize(); + if ( ! c ) { - auto c = v->AsOpaqueVal()->Serialize(); - if ( ! c ) - { - reporter->Error("unsupported opaque type for serialization"); - break; - } - - return {c}; + reporter->Error("unsupported opaque type for serialization"); + break; } + + return {c}; + } default: reporter->Error("unsupported Broker::Data type: %s", type_name(v->GetType()->Tag())); break; diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index bf11f840ff..65a70c4316 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -1024,22 +1024,22 @@ void Manager::DispatchMessage(const broker::topic& topic, broker::data msg) break; case broker::zeek::Message::Type::Batch: + { + broker::zeek::Batch batch(std::move(msg)); + + if ( ! batch.valid() ) { - broker::zeek::Batch batch(std::move(msg)); - - if ( ! batch.valid() ) - { - reporter->Warning("received invalid broker Batch: %s", - broker::to_string(batch).data()); - return; - } - - for ( auto& i : batch.batch() ) - DispatchMessage(topic, std::move(i)); - - break; + reporter->Warning("received invalid broker Batch: %s", + broker::to_string(batch).data()); + return; } + for ( auto& i : batch.batch() ) + DispatchMessage(topic, std::move(i)); + + break; + } + default: // We ignore unknown types so that we could add more in the // future if we had too. diff --git a/src/broker/Store.cc b/src/broker/Store.cc index 5a36fc9f47..d548657a17 100644 --- a/src/broker/Store.cc +++ b/src/broker/Store.cc @@ -69,11 +69,10 @@ broker::backend_options to_backend_options(broker::backend backend, RecordVal* o switch ( backend ) { case broker::backend::sqlite: - { - auto path = - options->GetFieldAs(0)->GetFieldAs(0)->CheckString(); - return {{"path", path}}; - } + { + auto path = options->GetFieldAs(0)->GetFieldAs(0)->CheckString(); + return {{"path", path}}; + } default: break; diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index 659c2f9f63..20e43514eb 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -493,32 +493,32 @@ unsigned int X509::KeyLength(EVP_PKEY* key) #ifndef OPENSSL_NO_EC case EVP_PKEY_EC: + { + BIGNUM* ec_order = BN_new(); + if ( ! ec_order ) + // could not malloc bignum? + return 0; + + const EC_GROUP* group = EC_KEY_get0_group(EVP_PKEY_get0_EC_KEY(key)); + + if ( ! group ) { - BIGNUM* ec_order = BN_new(); - if ( ! ec_order ) - // could not malloc bignum? - return 0; - - const EC_GROUP* group = EC_KEY_get0_group(EVP_PKEY_get0_EC_KEY(key)); - - if ( ! group ) - { - // unknown ex-group - BN_free(ec_order); - return 0; - } - - if ( ! EC_GROUP_get_order(group, ec_order, NULL) ) - { - // could not get ec-group-order - BN_free(ec_order); - return 0; - } - - unsigned int length = BN_num_bits(ec_order); + // unknown ex-group BN_free(ec_order); - return length; + return 0; } + + if ( ! EC_GROUP_get_order(group, ec_order, NULL) ) + { + // could not get ec-group-order + BN_free(ec_order); + return 0; + } + + unsigned int length = BN_num_bits(ec_order); + BN_free(ec_order); + return length; + } #endif default: return 0; // unknown public key type diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 63c4ff64a1..2869bfb9d2 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -841,28 +841,28 @@ bool Manager::IsCompatibleType(Type* t, bool atomic_only) return ! atomic_only; case TYPE_TABLE: - { - if ( atomic_only ) - return false; + { + if ( atomic_only ) + return false; - if ( ! t->IsSet() ) - return false; + if ( ! t->IsSet() ) + return false; - const auto& indices = t->AsSetType()->GetIndices(); + const auto& indices = t->AsSetType()->GetIndices(); - if ( indices->GetTypes().size() != 1 ) - return false; + if ( indices->GetTypes().size() != 1 ) + return false; - return IsCompatibleType(indices->GetPureType().get(), true); - } + return IsCompatibleType(indices->GetPureType().get(), true); + } case TYPE_VECTOR: - { - if ( atomic_only ) - return false; + { + if ( atomic_only ) + return false; - return IsCompatibleType(t->AsVectorType()->Yield().get(), true); - } + return IsCompatibleType(t->AsVectorType()->Yield().get(), true); + } default: return false; @@ -1999,65 +1999,65 @@ int Manager::GetValueLength(const Value* val) const case TYPE_STRING: case TYPE_ENUM: - { - length += val->val.string_val.length + 1; - break; - } + { + length += val->val.string_val.length + 1; + break; + } case TYPE_ADDR: + { + switch ( val->val.addr_val.family ) { - switch ( val->val.addr_val.family ) - { - case IPv4: - length += sizeof(val->val.addr_val.in.in4); - break; - case IPv6: - length += sizeof(val->val.addr_val.in.in6); - break; - default: - assert(false); - } + case IPv4: + length += sizeof(val->val.addr_val.in.in4); + break; + case IPv6: + length += sizeof(val->val.addr_val.in.in6); + break; + default: + assert(false); } + } break; case TYPE_SUBNET: + { + switch ( val->val.subnet_val.prefix.family ) { - switch ( val->val.subnet_val.prefix.family ) - { - case IPv4: - length += sizeof(val->val.subnet_val.prefix.in.in4) + - sizeof(val->val.subnet_val.length); - break; - case IPv6: - length += sizeof(val->val.subnet_val.prefix.in.in6) + - sizeof(val->val.subnet_val.length); - break; - default: - assert(false); - } + case IPv4: + length += sizeof(val->val.subnet_val.prefix.in.in4) + + sizeof(val->val.subnet_val.length); + break; + case IPv6: + length += sizeof(val->val.subnet_val.prefix.in.in6) + + sizeof(val->val.subnet_val.length); + break; + default: + assert(false); } + } break; case TYPE_PATTERN: - { - length += strlen(val->val.pattern_text_val) + 1; - break; - } + { + length += strlen(val->val.pattern_text_val) + 1; + break; + } case TYPE_TABLE: - { - for ( int i = 0; i < val->val.set_val.size; i++ ) - length += GetValueLength(val->val.set_val.vals[i]); - break; - } + { + for ( int i = 0; i < val->val.set_val.size; i++ ) + length += GetValueLength(val->val.set_val.vals[i]); + break; + } case TYPE_VECTOR: - { - int j = val->val.vector_val.size; - for ( int i = 0; i < j; i++ ) - length += GetValueLength(val->val.vector_val.vals[i]); - break; - } + { + int j = val->val.vector_val.size; + for ( int i = 0; i < j; i++ ) + length += GetValueLength(val->val.vector_val.vals[i]); + break; + } default: reporter->InternalError("unsupported type %d for GetValueLength", val->type); @@ -2084,16 +2084,16 @@ int Manager::CopyValue(char* data, const int startpos, const Value* val) const return sizeof(val->val.uint_val); case TYPE_PORT: - { - int length = 0; - memcpy(data + startpos, (const void*)&(val->val.port_val.port), - sizeof(val->val.port_val.port)); - length += sizeof(val->val.port_val.port); - memcpy(data + startpos + length, (const void*)&(val->val.port_val.proto), - sizeof(val->val.port_val.proto)); - length += sizeof(val->val.port_val.proto); - return length; - } + { + int length = 0; + memcpy(data + startpos, (const void*)&(val->val.port_val.port), + sizeof(val->val.port_val.port)); + length += sizeof(val->val.port_val.port); + memcpy(data + startpos + length, (const void*)&(val->val.port_val.proto), + sizeof(val->val.port_val.proto)); + length += sizeof(val->val.port_val.proto); + return length; + } case TYPE_DOUBLE: case TYPE_TIME: @@ -2104,92 +2104,92 @@ int Manager::CopyValue(char* data, const int startpos, const Value* val) const case TYPE_STRING: case TYPE_ENUM: - { - memcpy(data + startpos, val->val.string_val.data, val->val.string_val.length); - // Add a \0 to the end. To be able to hash zero-length - // strings and differentiate from !present. - memset(data + startpos + val->val.string_val.length, 0, 1); - return val->val.string_val.length + 1; - } + { + memcpy(data + startpos, val->val.string_val.data, val->val.string_val.length); + // Add a \0 to the end. To be able to hash zero-length + // strings and differentiate from !present. + memset(data + startpos + val->val.string_val.length, 0, 1); + return val->val.string_val.length + 1; + } case TYPE_ADDR: + { + int length = 0; + switch ( val->val.addr_val.family ) { - int length = 0; - switch ( val->val.addr_val.family ) - { - case IPv4: - length = sizeof(val->val.addr_val.in.in4); - memcpy(data + startpos, (const char*)&(val->val.addr_val.in.in4), length); - break; + case IPv4: + length = sizeof(val->val.addr_val.in.in4); + memcpy(data + startpos, (const char*)&(val->val.addr_val.in.in4), length); + break; - case IPv6: - length = sizeof(val->val.addr_val.in.in6); - memcpy(data + startpos, (const char*)&(val->val.addr_val.in.in6), length); - break; + case IPv6: + length = sizeof(val->val.addr_val.in.in6); + memcpy(data + startpos, (const char*)&(val->val.addr_val.in.in6), length); + break; - default: - assert(false); - } - - return length; + default: + assert(false); } + return length; + } + case TYPE_SUBNET: + { + int length = 0; + switch ( val->val.subnet_val.prefix.family ) { - int length = 0; - switch ( val->val.subnet_val.prefix.family ) - { - case IPv4: - length = sizeof(val->val.addr_val.in.in4); - memcpy(data + startpos, (const char*)&(val->val.subnet_val.prefix.in.in4), - length); - break; + case IPv4: + length = sizeof(val->val.addr_val.in.in4); + memcpy(data + startpos, (const char*)&(val->val.subnet_val.prefix.in.in4), + length); + break; - case IPv6: - length = sizeof(val->val.addr_val.in.in6); - memcpy(data + startpos, (const char*)&(val->val.subnet_val.prefix.in.in6), - length); - break; + case IPv6: + length = sizeof(val->val.addr_val.in.in6); + memcpy(data + startpos, (const char*)&(val->val.subnet_val.prefix.in.in6), + length); + break; - default: - assert(false); - } - - int lengthlength = sizeof(val->val.subnet_val.length); - memcpy(data + startpos + length, (const char*)&(val->val.subnet_val.length), - lengthlength); - length += lengthlength; - - return length; + default: + assert(false); } + int lengthlength = sizeof(val->val.subnet_val.length); + memcpy(data + startpos + length, (const char*)&(val->val.subnet_val.length), + lengthlength); + length += lengthlength; + + return length; + } + case TYPE_PATTERN: - { - // include null-terminator - int length = strlen(val->val.pattern_text_val) + 1; - memcpy(data + startpos, val->val.pattern_text_val, length); - return length; - } + { + // include null-terminator + int length = strlen(val->val.pattern_text_val) + 1; + memcpy(data + startpos, val->val.pattern_text_val, length); + return length; + } case TYPE_TABLE: - { - int length = 0; - int j = val->val.set_val.size; - for ( int i = 0; i < j; i++ ) - length += CopyValue(data, startpos + length, val->val.set_val.vals[i]); + { + int length = 0; + int j = val->val.set_val.size; + for ( int i = 0; i < j; i++ ) + length += CopyValue(data, startpos + length, val->val.set_val.vals[i]); - return length; - } + return length; + } case TYPE_VECTOR: - { - int length = 0; - int j = val->val.vector_val.size; - for ( int i = 0; i < j; i++ ) - length += CopyValue(data, startpos + length, val->val.vector_val.vals[i]); + { + int length = 0; + int j = val->val.vector_val.size; + for ( int i = 0; i < j; i++ ) + length += CopyValue(data, startpos + length, val->val.vector_val.vals[i]); - return length; - } + return length; + } default: reporter->InternalError("unsupported type %d for CopyValue", val->type); @@ -2284,134 +2284,133 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, Type* request_type, return new IntervalVal(val->val.double_val); case TYPE_STRING: - { - String* s = new String((const u_char*)val->val.string_val.data, - val->val.string_val.length, true); - return new StringVal(s); - } + { + String* s = new String((const u_char*)val->val.string_val.data, + val->val.string_val.length, true); + return new StringVal(s); + } case TYPE_PORT: return val_mgr->Port(val->val.port_val.port, val->val.port_val.proto)->Ref(); case TYPE_ADDR: + { + IPAddr* addr = nullptr; + switch ( val->val.addr_val.family ) { - IPAddr* addr = nullptr; - switch ( val->val.addr_val.family ) - { - case IPv4: - addr = new IPAddr(val->val.addr_val.in.in4); - break; + case IPv4: + addr = new IPAddr(val->val.addr_val.in.in4); + break; - case IPv6: - addr = new IPAddr(val->val.addr_val.in.in6); - break; + case IPv6: + addr = new IPAddr(val->val.addr_val.in.in6); + break; - default: - assert(false); - } - - auto* addrval = new AddrVal(*addr); - delete addr; - return addrval; + default: + assert(false); } + auto* addrval = new AddrVal(*addr); + delete addr; + return addrval; + } + case TYPE_SUBNET: + { + IPAddr* addr = nullptr; + switch ( val->val.subnet_val.prefix.family ) { - IPAddr* addr = nullptr; - switch ( val->val.subnet_val.prefix.family ) - { - case IPv4: - addr = new IPAddr(val->val.subnet_val.prefix.in.in4); - break; + case IPv4: + addr = new IPAddr(val->val.subnet_val.prefix.in.in4); + break; - case IPv6: - addr = new IPAddr(val->val.subnet_val.prefix.in.in6); - break; + case IPv6: + addr = new IPAddr(val->val.subnet_val.prefix.in.in6); + break; - default: - assert(false); - } - - auto* subnetval = new SubNetVal(*addr, val->val.subnet_val.length); - delete addr; - return subnetval; + default: + assert(false); } + auto* subnetval = new SubNetVal(*addr, val->val.subnet_val.length); + delete addr; + return subnetval; + } + case TYPE_PATTERN: - { - auto* re = new RE_Matcher(val->val.pattern_text_val); - re->Compile(); - return new PatternVal(re); - } + { + auto* re = new RE_Matcher(val->val.pattern_text_val); + re->Compile(); + return new PatternVal(re); + } case TYPE_TABLE: + { + // all entries have to have the same type... + const auto& type = request_type->AsTableType()->GetIndices()->GetPureType(); + auto set_index = make_intrusive(type); + set_index->Append(type); + auto s = make_intrusive(std::move(set_index), nullptr); + auto t = make_intrusive(std::move(s)); + for ( int j = 0; j < val->val.set_val.size; j++ ) { - // all entries have to have the same type... - const auto& type = request_type->AsTableType()->GetIndices()->GetPureType(); - auto set_index = make_intrusive(type); - set_index->Append(type); - auto s = make_intrusive(std::move(set_index), nullptr); - auto t = make_intrusive(std::move(s)); - for ( int j = 0; j < val->val.set_val.size; j++ ) - { - Val* assignval = - ValueToVal(i, val->val.set_val.vals[j], type.get(), have_error); + Val* assignval = ValueToVal(i, val->val.set_val.vals[j], type.get(), have_error); - if ( have_error ) - return nullptr; + if ( have_error ) + return nullptr; - t->Assign({AdoptRef{}, assignval}, nullptr); - } - - return t.release(); + t->Assign({AdoptRef{}, assignval}, nullptr); } + return t.release(); + } + case TYPE_VECTOR: + { + // all entries have to have the same type... + const auto& type = request_type->AsVectorType()->Yield(); + auto vt = make_intrusive(type); + auto v = make_intrusive(std::move(vt)); + + for ( int j = 0; j < val->val.vector_val.size; j++ ) { - // all entries have to have the same type... - const auto& type = request_type->AsVectorType()->Yield(); - auto vt = make_intrusive(type); - auto v = make_intrusive(std::move(vt)); + auto el = ValueToVal(i, val->val.vector_val.vals[j], type.get(), have_error); - for ( int j = 0; j < val->val.vector_val.size; j++ ) - { - auto el = ValueToVal(i, val->val.vector_val.vals[j], type.get(), have_error); + if ( have_error ) + return nullptr; - if ( have_error ) - return nullptr; - - v->Assign(j, {AdoptRef{}, el}); - } - - return v.release(); + v->Assign(j, {AdoptRef{}, el}); } + return v.release(); + } + case TYPE_ENUM: + { + // Convert to string first to not have to deal with missing + // \0's... + string enum_string(val->val.string_val.data, val->val.string_val.length); + + string module = zeek::detail::extract_module_name(enum_string.c_str()); + string var = zeek::detail::extract_var_name(enum_string.c_str()); + + // Well, this is kind of stupid, because EnumType just + // mangles the module name and the var name together again... + // but well. + bro_int_t index = request_type->AsEnumType()->Lookup(module, var.c_str()); + if ( index == -1 ) { - // Convert to string first to not have to deal with missing - // \0's... - string enum_string(val->val.string_val.data, val->val.string_val.length); + Warning(i, "Value '%s' for stream '%s' is not a valid enum.", enum_string.c_str(), + i->name.c_str()); - string module = zeek::detail::extract_module_name(enum_string.c_str()); - string var = zeek::detail::extract_var_name(enum_string.c_str()); - - // Well, this is kind of stupid, because EnumType just - // mangles the module name and the var name together again... - // but well. - bro_int_t index = request_type->AsEnumType()->Lookup(module, var.c_str()); - if ( index == -1 ) - { - Warning(i, "Value '%s' for stream '%s' is not a valid enum.", - enum_string.c_str(), i->name.c_str()); - - have_error = true; - return nullptr; - } - - auto rval = request_type->AsEnumType()->GetEnumVal(index); - return rval.release(); + have_error = true; + return nullptr; } + auto rval = request_type->AsEnumType()->GetEnumVal(index); + return rval.release(); + } + default: reporter->InternalError("Unsupported type for input_read in stream %s", i->name.c_str()); diff --git a/src/input/readers/ascii/Ascii.cc b/src/input/readers/ascii/Ascii.cc index fb83073bc4..2a001f04fa 100644 --- a/src/input/readers/ascii/Ascii.cc +++ b/src/input/readers/ascii/Ascii.cc @@ -281,59 +281,59 @@ bool Ascii::DoUpdate() switch ( Info().mode ) { case MODE_REREAD: + { + // check if the file has changed + struct stat sb; + if ( stat(fname.c_str(), &sb) == -1 ) { - // check if the file has changed - struct stat sb; - if ( stat(fname.c_str(), &sb) == -1 ) - { - FailWarn(fail_on_file_problem, Fmt("Could not get stat for %s", fname.c_str()), - true); + FailWarn(fail_on_file_problem, Fmt("Could not get stat for %s", fname.c_str()), + true); - file.close(); - return ! fail_on_file_problem; - } - - if ( sb.st_ino == ino && sb.st_mtime == mtime ) - // no change - return true; - - // Warn again in case of trouble if the file changes. The comparison to 0 - // is to suppress an extra warning that we'd otherwise get on the initial - // inode assignment. - if ( ino != 0 ) - StopWarningSuppression(); - - mtime = sb.st_mtime; - ino = sb.st_ino; - // File changed. Fall through to re-read. + file.close(); + return ! fail_on_file_problem; } + if ( sb.st_ino == ino && sb.st_mtime == mtime ) + // no change + return true; + + // Warn again in case of trouble if the file changes. The comparison to 0 + // is to suppress an extra warning that we'd otherwise get on the initial + // inode assignment. + if ( ino != 0 ) + StopWarningSuppression(); + + mtime = sb.st_mtime; + ino = sb.st_ino; + // File changed. Fall through to re-read. + } + case MODE_MANUAL: case MODE_STREAM: + { + // dirty, fix me. (well, apparently after trying seeking, etc + // - this is not that bad) + if ( file.is_open() ) { - // dirty, fix me. (well, apparently after trying seeking, etc - // - this is not that bad) - if ( file.is_open() ) + if ( Info().mode == MODE_STREAM ) { - if ( Info().mode == MODE_STREAM ) + file.clear(); // remove end of file evil bits + if ( ! ReadHeader(true) ) { - file.clear(); // remove end of file evil bits - if ( ! ReadHeader(true) ) - { - return ! fail_on_file_problem; // header reading failed - } - - break; + return ! fail_on_file_problem; // header reading failed } - file.close(); + break; } - OpenFile(); - - break; + file.close(); } + OpenFile(); + + break; + } + default: assert(false); } diff --git a/src/input/readers/benchmark/Benchmark.cc b/src/input/readers/benchmark/Benchmark.cc index 0b92ad6ec8..89beb3a9eb 100644 --- a/src/input/readers/benchmark/Benchmark.cc +++ b/src/input/readers/benchmark/Benchmark.cc @@ -134,12 +134,12 @@ threading::Value* Benchmark::EntryToVal(TypeTag type, TypeTag subtype) assert(false); // no enums, please. case TYPE_STRING: - { - std::string rnd = RandomString(10); - val->val.string_val.data = util::copy_string(rnd.c_str()); - val->val.string_val.length = rnd.size(); - break; - } + { + std::string rnd = RandomString(10); + val->val.string_val.data = util::copy_string(rnd.c_str()); + val->val.string_val.length = rnd.size(); + break; + } case TYPE_BOOL: val->val.int_val = 1; // we never lie. @@ -168,10 +168,10 @@ threading::Value* Benchmark::EntryToVal(TypeTag type, TypeTag subtype) break; case TYPE_SUBNET: - { - val->val.subnet_val.prefix = ascii->ParseAddr("192.168.17.1"); - val->val.subnet_val.length = 16; - } + { + val->val.subnet_val.prefix = ascii->ParseAddr("192.168.17.1"); + val->val.subnet_val.length = 16; + } break; case TYPE_ADDR: diff --git a/src/input/readers/binary/Binary.cc b/src/input/readers/binary/Binary.cc index 526a48bc82..a12bab3023 100644 --- a/src/input/readers/binary/Binary.cc +++ b/src/input/readers/binary/Binary.cc @@ -199,20 +199,20 @@ bool Binary::DoUpdate() switch ( Info().mode ) { case MODE_REREAD: + { + switch ( UpdateModificationTime() ) { - switch ( UpdateModificationTime() ) - { - case -1: - return false; // error - case 0: - return true; // no change - case 1: - break; // file changed. reread. - default: - assert(false); - } - // fallthrough + case -1: + return false; // error + case 0: + return true; // no change + case 1: + break; // file changed. reread. + default: + assert(false); } + // fallthrough + } case MODE_MANUAL: case MODE_STREAM: diff --git a/src/input/readers/config/Config.cc b/src/input/readers/config/Config.cc index 2bafa9c30d..011498f059 100644 --- a/src/input/readers/config/Config.cc +++ b/src/input/readers/config/Config.cc @@ -118,54 +118,54 @@ bool Config::DoUpdate() switch ( Info().mode ) { case MODE_REREAD: + { + // check if the file has changed + struct stat sb; + if ( stat(Info().source, &sb) == -1 ) { - // check if the file has changed - struct stat sb; - if ( stat(Info().source, &sb) == -1 ) - { - FailWarn(fail_on_file_problem, Fmt("Could not get stat for %s", Info().source), - true); + FailWarn(fail_on_file_problem, Fmt("Could not get stat for %s", Info().source), + true); - file.close(); - return ! fail_on_file_problem; - } - - if ( sb.st_ino == ino && sb.st_mtime == mtime ) - // no change - return true; - - // Warn again in case of trouble if the file changes. The comparison to 0 - // is to suppress an extra warning that we'd otherwise get on the initial - // inode assignment. - if ( ino != 0 ) - StopWarningSuppression(); - - mtime = sb.st_mtime; - ino = sb.st_ino; - // File changed. Fall through to re-read. + file.close(); + return ! fail_on_file_problem; } + if ( sb.st_ino == ino && sb.st_mtime == mtime ) + // no change + return true; + + // Warn again in case of trouble if the file changes. The comparison to 0 + // is to suppress an extra warning that we'd otherwise get on the initial + // inode assignment. + if ( ino != 0 ) + StopWarningSuppression(); + + mtime = sb.st_mtime; + ino = sb.st_ino; + // File changed. Fall through to re-read. + } + case MODE_MANUAL: case MODE_STREAM: + { + // dirty, fix me. (well, apparently after trying seeking, etc + // - this is not that bad) + if ( file.is_open() ) { - // dirty, fix me. (well, apparently after trying seeking, etc - // - this is not that bad) - if ( file.is_open() ) + if ( Info().mode == MODE_STREAM ) { - if ( Info().mode == MODE_STREAM ) - { - file.clear(); // remove end of file evil bits - break; - } - - file.close(); + file.clear(); // remove end of file evil bits + break; } - OpenFile(); - - break; + file.close(); } + OpenFile(); + + break; + } + default: assert(false); } diff --git a/src/input/readers/raw/Raw.cc b/src/input/readers/raw/Raw.cc index 27b1c54831..1d938f6be4 100644 --- a/src/input/readers/raw/Raw.cc +++ b/src/input/readers/raw/Raw.cc @@ -558,27 +558,27 @@ bool Raw::DoUpdate() switch ( Info().mode ) { case MODE_REREAD: + { + assert(childpid == -1); // mode may not be used to execute child programs + // check if the file has changed + struct stat sb; + if ( stat(fname.c_str(), &sb) == -1 ) { - assert(childpid == -1); // mode may not be used to execute child programs - // check if the file has changed - struct stat sb; - if ( stat(fname.c_str(), &sb) == -1 ) - { - Error(Fmt("Could not get stat for %s", fname.c_str())); - return false; - } - - if ( sb.st_ino == ino && sb.st_mtime == mtime ) - // no change - return true; - - mtime = sb.st_mtime; - ino = sb.st_ino; - // file changed. reread. - // - // fallthrough + Error(Fmt("Could not get stat for %s", fname.c_str())); + return false; } + if ( sb.st_ino == ino && sb.st_mtime == mtime ) + // no change + return true; + + mtime = sb.st_mtime; + ino = sb.st_ino; + // file changed. reread. + // + // fallthrough + } + case MODE_MANUAL: case MODE_STREAM: if ( Info().mode == MODE_STREAM && file ) diff --git a/src/input/readers/sqlite/SQLite.cc b/src/input/readers/sqlite/SQLite.cc index ebc1c52b5a..a415377cda 100644 --- a/src/input/readers/sqlite/SQLite.cc +++ b/src/input/readers/sqlite/SQLite.cc @@ -136,40 +136,40 @@ Value* SQLite::EntryToVal(sqlite3_stmt* st, const threading::Field* field, int p { case TYPE_ENUM: case TYPE_STRING: - { - const char* text = (const char*)sqlite3_column_text(st, pos); - int length = sqlite3_column_bytes(st, pos); + { + const char* text = (const char*)sqlite3_column_text(st, pos); + int length = sqlite3_column_bytes(st, pos); - char* out = new char[length]; - memcpy(out, text, length); + char* out = new char[length]; + memcpy(out, text, length); - val->val.string_val.length = length; - val->val.string_val.data = out; - break; - } + val->val.string_val.length = length; + val->val.string_val.data = out; + break; + } case TYPE_BOOL: + { + if ( sqlite3_column_type(st, pos) != SQLITE_INTEGER ) { - if ( sqlite3_column_type(st, pos) != SQLITE_INTEGER ) - { - Error("Invalid data type for boolean - expected Integer"); - delete val; - return nullptr; - } - - int res = sqlite3_column_int(st, pos); - - if ( res == 0 || res == 1 ) - val->val.int_val = res; - else - { - Error(Fmt("Invalid value for boolean: %d", res)); - delete val; - return nullptr; - } - break; + Error("Invalid data type for boolean - expected Integer"); + delete val; + return nullptr; } + int res = sqlite3_column_int(st, pos); + + if ( res == 0 || res == 1 ) + val->val.int_val = res; + else + { + Error(Fmt("Invalid value for boolean: %d", res)); + delete val; + return nullptr; + } + break; + } + case TYPE_INT: val->val.int_val = sqlite3_column_int64(st, pos); break; @@ -185,54 +185,54 @@ Value* SQLite::EntryToVal(sqlite3_stmt* st, const threading::Field* field, int p break; case TYPE_PORT: + { + val->val.port_val.port = sqlite3_column_int(st, pos); + val->val.port_val.proto = TRANSPORT_UNKNOWN; + if ( subpos != -1 ) { - val->val.port_val.port = sqlite3_column_int(st, pos); - val->val.port_val.proto = TRANSPORT_UNKNOWN; - if ( subpos != -1 ) - { - const char* text = (const char*)sqlite3_column_text(st, subpos); + const char* text = (const char*)sqlite3_column_text(st, subpos); - if ( text == 0 ) - Error("Port protocol definition did not contain text"); - else - { - std::string s(text, sqlite3_column_bytes(st, subpos)); - val->val.port_val.proto = io->ParseProto(s); - } + if ( text == 0 ) + Error("Port protocol definition did not contain text"); + else + { + std::string s(text, sqlite3_column_bytes(st, subpos)); + val->val.port_val.proto = io->ParseProto(s); } - break; } + break; + } case TYPE_SUBNET: - { - const char* text = (const char*)sqlite3_column_text(st, pos); - std::string s(text, sqlite3_column_bytes(st, pos)); - int pos = s.find('/'); - int width = atoi(s.substr(pos + 1).c_str()); - std::string addr = s.substr(0, pos); + { + const char* text = (const char*)sqlite3_column_text(st, pos); + std::string s(text, sqlite3_column_bytes(st, pos)); + int pos = s.find('/'); + int width = atoi(s.substr(pos + 1).c_str()); + std::string addr = s.substr(0, pos); - val->val.subnet_val.prefix = io->ParseAddr(addr); - val->val.subnet_val.length = width; - break; - } + val->val.subnet_val.prefix = io->ParseAddr(addr); + val->val.subnet_val.length = width; + break; + } case TYPE_ADDR: - { - const char* text = (const char*)sqlite3_column_text(st, pos); - std::string s(text, sqlite3_column_bytes(st, pos)); - val->val.addr_val = io->ParseAddr(s); - break; - } + { + const char* text = (const char*)sqlite3_column_text(st, pos); + std::string s(text, sqlite3_column_bytes(st, pos)); + val->val.addr_val = io->ParseAddr(s); + break; + } case TYPE_TABLE: case TYPE_VECTOR: - { - const char* text = (const char*)sqlite3_column_text(st, pos); - std::string s(text, sqlite3_column_bytes(st, pos)); - delete val; - val = io->ParseValue(s, "", field->type, field->subtype); - break; - } + { + const char* text = (const char*)sqlite3_column_text(st, pos); + std::string s(text, sqlite3_column_bytes(st, pos)); + delete val; + val = io->ParseValue(s, "", field->type, field->subtype); + break; + } default: Error(Fmt("unsupported field format %d", field->type)); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index fe29d4ab92..8cd1adc099 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -952,24 +952,24 @@ threading::Value* Manager::ValToLogVal(Val* val, Type* ty) break; case TYPE_ENUM: + { + const char* s = val->GetType()->AsEnumType()->Lookup(val->InternalInt()); + + if ( s ) { - const char* s = val->GetType()->AsEnumType()->Lookup(val->InternalInt()); - - if ( s ) - { - lval->val.string_val.data = util::copy_string(s); - lval->val.string_val.length = strlen(s); - } - - else - { - val->GetType()->Error("enum type does not contain value", val); - lval->val.string_val.data = util::copy_string(""); - lval->val.string_val.length = 0; - } - break; + lval->val.string_val.data = util::copy_string(s); + lval->val.string_val.length = strlen(s); } + else + { + val->GetType()->Error("enum type does not contain value", val); + lval->val.string_val.data = util::copy_string(""); + lval->val.string_val.length = 0; + } + break; + } + case TYPE_COUNT: lval->val.uint_val = val->InternalUnsigned(); break; @@ -994,68 +994,68 @@ threading::Value* Manager::ValToLogVal(Val* val, Type* ty) break; case TYPE_STRING: - { - const String* s = val->AsString(); - char* buf = new char[s->Len()]; - memcpy(buf, s->Bytes(), s->Len()); + { + const String* s = val->AsString(); + char* buf = new char[s->Len()]; + memcpy(buf, s->Bytes(), s->Len()); - lval->val.string_val.data = buf; - lval->val.string_val.length = s->Len(); - break; - } + lval->val.string_val.data = buf; + lval->val.string_val.length = s->Len(); + break; + } case TYPE_FILE: - { - const File* f = val->AsFile(); - string s = f->Name(); - lval->val.string_val.data = util::copy_string(s.c_str()); - lval->val.string_val.length = s.size(); - break; - } + { + const File* f = val->AsFile(); + string s = f->Name(); + lval->val.string_val.data = util::copy_string(s.c_str()); + lval->val.string_val.length = s.size(); + break; + } case TYPE_FUNC: - { - ODesc d; - const Func* f = val->AsFunc(); - f->Describe(&d); - const char* s = d.Description(); - lval->val.string_val.data = util::copy_string(s); - lval->val.string_val.length = strlen(s); - break; - } + { + ODesc d; + const Func* f = val->AsFunc(); + f->Describe(&d); + const char* s = d.Description(); + lval->val.string_val.data = util::copy_string(s); + lval->val.string_val.length = strlen(s); + break; + } case TYPE_TABLE: - { - auto set = val->AsTableVal()->ToPureListVal(); - if ( ! set ) - // ToPureListVal has reported an internal warning - // already. Just keep going by making something up. - set = make_intrusive(TYPE_INT); + { + auto set = val->AsTableVal()->ToPureListVal(); + if ( ! set ) + // ToPureListVal has reported an internal warning + // already. Just keep going by making something up. + set = make_intrusive(TYPE_INT); - lval->val.set_val.size = set->Length(); - lval->val.set_val.vals = new threading::Value*[lval->val.set_val.size]; + lval->val.set_val.size = set->Length(); + lval->val.set_val.vals = new threading::Value*[lval->val.set_val.size]; - for ( bro_int_t i = 0; i < lval->val.set_val.size; i++ ) - lval->val.set_val.vals[i] = ValToLogVal(set->Idx(i).get()); + for ( bro_int_t i = 0; i < lval->val.set_val.size; i++ ) + lval->val.set_val.vals[i] = ValToLogVal(set->Idx(i).get()); - break; - } + break; + } case TYPE_VECTOR: + { + VectorVal* vec = val->AsVectorVal(); + lval->val.vector_val.size = vec->Size(); + lval->val.vector_val.vals = new threading::Value*[lval->val.vector_val.size]; + + for ( bro_int_t i = 0; i < lval->val.vector_val.size; i++ ) { - VectorVal* vec = val->AsVectorVal(); - lval->val.vector_val.size = vec->Size(); - lval->val.vector_val.vals = new threading::Value*[lval->val.vector_val.size]; - - for ( bro_int_t i = 0; i < lval->val.vector_val.size; i++ ) - { - lval->val.vector_val.vals[i] = - ValToLogVal(vec->ValAt(i).get(), vec->GetType()->Yield().get()); - } - - break; + lval->val.vector_val.vals[i] = + ValToLogVal(vec->ValAt(i).get(), vec->GetType()->Yield().get()); } + break; + } + default: reporter->InternalError("unsupported type %s for log_write", type_name(lval->type)); } diff --git a/src/logging/writers/sqlite/SQLite.cc b/src/logging/writers/sqlite/SQLite.cc index 6bdaf718fa..440c62d01c 100644 --- a/src/logging/writers/sqlite/SQLite.cc +++ b/src/logging/writers/sqlite/SQLite.cc @@ -254,16 +254,16 @@ int SQLite::AddParams(Value* val, int pos) return sqlite3_bind_int(st, pos, val->val.port_val.port); case TYPE_SUBNET: - { - string out = io->Render(val->val.subnet_val); - return sqlite3_bind_text(st, pos, out.data(), out.size(), SQLITE_TRANSIENT); - } + { + string out = io->Render(val->val.subnet_val); + return sqlite3_bind_text(st, pos, out.data(), out.size(), SQLITE_TRANSIENT); + } case TYPE_ADDR: - { - string out = io->Render(val->val.addr_val); - return sqlite3_bind_text(st, pos, out.data(), out.size(), SQLITE_TRANSIENT); - } + { + string out = io->Render(val->val.addr_val); + return sqlite3_bind_text(st, pos, out.data(), out.size(), SQLITE_TRANSIENT); + } case TYPE_TIME: case TYPE_INTERVAL: @@ -274,59 +274,59 @@ int SQLite::AddParams(Value* val, int pos) case TYPE_STRING: case TYPE_FILE: case TYPE_FUNC: - { - if ( ! val->val.string_val.length || val->val.string_val.length == 0 ) - return sqlite3_bind_null(st, pos); + { + if ( ! val->val.string_val.length || val->val.string_val.length == 0 ) + return sqlite3_bind_null(st, pos); - return sqlite3_bind_text(st, pos, val->val.string_val.data, - val->val.string_val.length, SQLITE_TRANSIENT); - } + return sqlite3_bind_text(st, pos, val->val.string_val.data, val->val.string_val.length, + SQLITE_TRANSIENT); + } case TYPE_TABLE: - { - ODesc desc; - desc.Clear(); - desc.EnableEscaping(); - desc.AddEscapeSequence(set_separator); + { + ODesc desc; + desc.Clear(); + desc.EnableEscaping(); + desc.AddEscapeSequence(set_separator); - if ( ! val->val.set_val.size ) - desc.Add(empty_field); - else - for ( bro_int_t j = 0; j < val->val.set_val.size; j++ ) - { - if ( j > 0 ) - desc.AddRaw(set_separator); + if ( ! val->val.set_val.size ) + desc.Add(empty_field); + else + for ( bro_int_t j = 0; j < val->val.set_val.size; j++ ) + { + if ( j > 0 ) + desc.AddRaw(set_separator); - io->Describe(&desc, val->val.set_val.vals[j], fields[pos - 1]->name); - } + io->Describe(&desc, val->val.set_val.vals[j], fields[pos - 1]->name); + } - desc.RemoveEscapeSequence(set_separator); - return sqlite3_bind_text(st, pos, (const char*)desc.Bytes(), desc.Len(), - SQLITE_TRANSIENT); - } + desc.RemoveEscapeSequence(set_separator); + return sqlite3_bind_text(st, pos, (const char*)desc.Bytes(), desc.Len(), + SQLITE_TRANSIENT); + } case TYPE_VECTOR: - { - ODesc desc; - desc.Clear(); - desc.EnableEscaping(); - desc.AddEscapeSequence(set_separator); + { + ODesc desc; + desc.Clear(); + desc.EnableEscaping(); + desc.AddEscapeSequence(set_separator); - if ( ! val->val.vector_val.size ) - desc.Add(empty_field); - else - for ( bro_int_t j = 0; j < val->val.vector_val.size; j++ ) - { - if ( j > 0 ) - desc.AddRaw(set_separator); + if ( ! val->val.vector_val.size ) + desc.Add(empty_field); + else + for ( bro_int_t j = 0; j < val->val.vector_val.size; j++ ) + { + if ( j > 0 ) + desc.AddRaw(set_separator); - io->Describe(&desc, val->val.vector_val.vals[j], fields[pos - 1]->name); - } + io->Describe(&desc, val->val.vector_val.vals[j], fields[pos - 1]->name); + } - desc.RemoveEscapeSequence(set_separator); - return sqlite3_bind_text(st, pos, (const char*)desc.Bytes(), desc.Len(), - SQLITE_TRANSIENT); - } + desc.RemoveEscapeSequence(set_separator); + return sqlite3_bind_text(st, pos, (const char*)desc.Bytes(), desc.Len(), + SQLITE_TRANSIENT); + } default: Error(Fmt("unsupported field format %d", val->type)); diff --git a/src/packet_analysis/protocol/arp/ARP.cc b/src/packet_analysis/protocol/arp/ARP.cc index 00da3182a2..ce70264058 100644 --- a/src/packet_analysis/protocol/arp/ARP.cc +++ b/src/packet_analysis/protocol/arp/ARP.cc @@ -115,11 +115,11 @@ bool ARPAnalyzer::AnalyzePacket(size_t len, const uint8_t* data, Packet* packet) break; default: - { - // don't know how to proceed - BadARPEvent(ah, "unknown-arp-hw-address (hrd=%i)", ntohs(ah->ar_hrd)); - return false; - } + { + // don't know how to proceed + BadARPEvent(ah, "unknown-arp-hw-address (hrd=%i)", ntohs(ah->ar_hrd)); + return false; + } } // Note: We don't support IPv6 addresses. @@ -136,11 +136,11 @@ bool ARPAnalyzer::AnalyzePacket(size_t len, const uint8_t* data, Packet* packet) break; default: - { - // don't know how to proceed - BadARPEvent(ah, "unknown-arp-proto-address (pro=%i)", ntohs(ah->ar_pro)); - return false; - } + { + // don't know how to proceed + BadARPEvent(ah, "unknown-arp-proto-address (pro=%i)", ntohs(ah->ar_pro)); + return false; + } } // Check MAC src address = ARP sender MAC address. @@ -167,18 +167,18 @@ bool ARPAnalyzer::AnalyzePacket(size_t len, const uint8_t* data, Packet* packet) case ARPOP_REVREPLY: case ARPOP_INVREQUEST: case ARPOP_INVREPLY: - { - // don't know how to handle the opcode - BadARPEvent(ah, "unimplemented-arp-opcode (%i)", ntohs(ah->ar_op)); - return false; - } + { + // don't know how to handle the opcode + BadARPEvent(ah, "unimplemented-arp-opcode (%i)", ntohs(ah->ar_op)); + return false; + } default: - { - // invalid opcode - BadARPEvent(ah, "invalid-arp-opcode (opcode=%i)", ntohs(ah->ar_op)); - return false; - } + { + // invalid opcode + BadARPEvent(ah, "invalid-arp-opcode (opcode=%i)", ntohs(ah->ar_op)); + return false; + } } // Leave packet analyzer land diff --git a/src/packet_analysis/protocol/icmp/ICMP.cc b/src/packet_analysis/protocol/icmp/ICMP.cc index b6cf3689c3..4913859b18 100644 --- a/src/packet_analysis/protocol/icmp/ICMP.cc +++ b/src/packet_analysis/protocol/icmp/ICMP.cc @@ -274,36 +274,36 @@ TransportProto ICMPAnalyzer::GetContextProtocol(const IP_Hdr* ip_hdr, uint32_t* switch ( proto ) { case TRANSPORT_ICMP: - { - const struct icmp* icmpp = (const struct icmp*)transport_hdr; - bool is_one_way; // dummy - *src_port = ntohs(icmpp->icmp_type); + { + const struct icmp* icmpp = (const struct icmp*)transport_hdr; + bool is_one_way; // dummy + *src_port = ntohs(icmpp->icmp_type); - if ( ip4 ) - *dst_port = - ntohs(ICMP4_counterpart(icmpp->icmp_type, icmpp->icmp_code, is_one_way)); - else - *dst_port = - ntohs(ICMP6_counterpart(icmpp->icmp_type, icmpp->icmp_code, is_one_way)); + if ( ip4 ) + *dst_port = + ntohs(ICMP4_counterpart(icmpp->icmp_type, icmpp->icmp_code, is_one_way)); + else + *dst_port = + ntohs(ICMP6_counterpart(icmpp->icmp_type, icmpp->icmp_code, is_one_way)); - break; - } + break; + } case TRANSPORT_TCP: - { - const struct tcphdr* tp = (const struct tcphdr*)transport_hdr; - *src_port = ntohs(tp->th_sport); - *dst_port = ntohs(tp->th_dport); - break; - } + { + const struct tcphdr* tp = (const struct tcphdr*)transport_hdr; + *src_port = ntohs(tp->th_sport); + *dst_port = ntohs(tp->th_dport); + break; + } case TRANSPORT_UDP: - { - const struct udphdr* up = (const struct udphdr*)transport_hdr; - *src_port = ntohs(up->uh_sport); - *dst_port = ntohs(up->uh_dport); - break; - } + { + const struct udphdr* up = (const struct udphdr*)transport_hdr; + *src_port = ntohs(up->uh_sport); + *dst_port = ntohs(up->uh_dport); + break; + } default: *src_port = *dst_port = ntohs(0); @@ -749,10 +749,10 @@ zeek::VectorValPtr ICMPAnalyzer::BuildNDOptionsVal(int caplen, const u_char* dat } default: - { - set_payload_field = true; - break; - } + { + set_payload_field = true; + break; + } } if ( set_payload_field ) diff --git a/src/packet_analysis/protocol/wrapper/Wrapper.cc b/src/packet_analysis/protocol/wrapper/Wrapper.cc index eb35de24d8..f88e6ce3b6 100644 --- a/src/packet_analysis/protocol/wrapper/Wrapper.cc +++ b/src/packet_analysis/protocol/wrapper/Wrapper.cc @@ -48,45 +48,45 @@ bool WrapperAnalyzer::Analyze(Packet* packet, const uint8_t*& data) // 802.1q / 802.1ad case 0x8100: case 0x9100: + { + if ( data + 4 >= end_of_data ) { - if ( data + 4 >= end_of_data ) - { - Weird("truncated_link_header", packet); - return false; - } - - auto& vlan_ref = saw_vlan ? packet->inner_vlan : packet->vlan; - vlan_ref = ((data[0] << 8u) + data[1]) & 0xfff; - protocol = ((data[2] << 8u) + data[3]); - data += 4; // Skip the vlan header - saw_vlan = true; - packet->eth_type = protocol; + Weird("truncated_link_header", packet); + return false; } + + auto& vlan_ref = saw_vlan ? packet->inner_vlan : packet->vlan; + vlan_ref = ((data[0] << 8u) + data[1]) & 0xfff; + protocol = ((data[2] << 8u) + data[3]); + data += 4; // Skip the vlan header + saw_vlan = true; + packet->eth_type = protocol; + } break; // PPPoE carried over the ethernet frame. case 0x8864: + { + if ( data + 8 >= end_of_data ) { - if ( data + 8 >= end_of_data ) - { - Weird("truncated_link_header", packet); - return false; - } - - protocol = (data[6] << 8u) + data[7]; - data += 8; // Skip the PPPoE session and PPP header - - if ( protocol == 0x0021 ) - packet->l3_proto = L3_IPV4; - else if ( protocol == 0x0057 ) - packet->l3_proto = L3_IPV6; - else - { - // Neither IPv4 nor IPv6. - Weird("non_ip_packet_in_pppoe_encapsulation", packet); - return false; - } + Weird("truncated_link_header", packet); + return false; } + + protocol = (data[6] << 8u) + data[7]; + data += 8; // Skip the PPPoE session and PPP header + + if ( protocol == 0x0021 ) + packet->l3_proto = L3_IPV4; + else if ( protocol == 0x0057 ) + packet->l3_proto = L3_IPV6; + else + { + // Neither IPv4 nor IPv6. + Weird("non_ip_packet_in_pppoe_encapsulation", packet); + return false; + } + } break; } } diff --git a/src/plugin/Plugin.cc b/src/plugin/Plugin.cc index 69bb7f79e8..c569b1afeb 100644 --- a/src/plugin/Plugin.cc +++ b/src/plugin/Plugin.cc @@ -168,57 +168,57 @@ void HookArgument::Describe(ODesc* d) const break; case WRITER_INFO: + { + d->Add(arg.winfo->path); + d->Add("("); + d->Add(arg.winfo->network_time); + d->Add(","); + d->Add(arg.winfo->rotation_interval); + d->Add(","); + d->Add(arg.winfo->rotation_base); + + if ( arg.winfo->config.size() > 0 ) { - d->Add(arg.winfo->path); - d->Add("("); - d->Add(arg.winfo->network_time); - d->Add(","); - d->Add(arg.winfo->rotation_interval); - d->Add(","); - d->Add(arg.winfo->rotation_base); + bool first = true; + d->Add("config: {"); - if ( arg.winfo->config.size() > 0 ) + for ( auto& v : arg.winfo->config ) { - bool first = true; - d->Add("config: {"); - - for ( auto& v : arg.winfo->config ) - { - if ( ! first ) - d->Add(", "); - - d->Add(v.first); - d->Add(": "); - d->Add(v.second); - first = false; - } - - d->Add("}"); - } - - d->Add(")"); - } - break; - - case THREAD_FIELDS: - { - d->Add("{"); - - for ( int i = 0; i < tfields.first; i++ ) - { - const threading::Field* f = tfields.second[i]; - - if ( i > 0 ) + if ( ! first ) d->Add(", "); - d->Add(f->name); - d->Add(" ("); - d->Add(f->TypeName()); - d->Add(")"); + d->Add(v.first); + d->Add(": "); + d->Add(v.second); + first = false; } d->Add("}"); } + + d->Add(")"); + } + break; + + case THREAD_FIELDS: + { + d->Add("{"); + + for ( int i = 0; i < tfields.first; i++ ) + { + const threading::Field* f = tfields.second[i]; + + if ( i > 0 ) + d->Add(", "); + + d->Add(f->name); + d->Add(" ("); + d->Add(f->TypeName()); + d->Add(")"); + } + + d->Add("}"); + } break; case LOCATION: diff --git a/src/script_opt/CPP/Consts.cc b/src/script_opt/CPP/Consts.cc index e69a9b963b..c21a1db9b8 100644 --- a/src/script_opt/CPP/Consts.cc +++ b/src/script_opt/CPP/Consts.cc @@ -127,17 +127,17 @@ bool CPPCompile::AddConstant(const ValPtr& vp) case TYPE_ADDR: case TYPE_SUBNET: - { - auto prefix = (tag == TYPE_ADDR) ? "Addr" : "SubNet"; + { + auto prefix = (tag == TYPE_ADDR) ? "Addr" : "SubNet"; - Emit("%sValPtr %s;", prefix, const_name); + Emit("%sValPtr %s;", prefix, const_name); - ODesc d; - v->Describe(&d); + ODesc d; + v->Describe(&d); - AddInit(v, const_name, - string("make_intrusive<") + prefix + "Val>(\"" + d.Description() + "\")"); - } + AddInit(v, const_name, + string("make_intrusive<") + prefix + "Val>(\"" + d.Description() + "\")"); + } break; case TYPE_FUNC: @@ -151,15 +151,15 @@ bool CPPCompile::AddConstant(const ValPtr& vp) break; case TYPE_FILE: - { - Emit("FileValPtr %s;", const_name); + { + Emit("FileValPtr %s;", const_name); - auto f = cast_intrusive(vp)->Get(); + auto f = cast_intrusive(vp)->Get(); - AddInit(v, const_name, - string("make_intrusive(") + "make_intrusive(\"" + f->Name() + - "\", \"w\"))"); - } + AddInit(v, const_name, + string("make_intrusive(") + "make_intrusive(\"" + f->Name() + + "\", \"w\"))"); + } break; default: diff --git a/src/script_opt/CPP/Inits.cc b/src/script_opt/CPP/Inits.cc index d75d3bcc73..d6f41da620 100644 --- a/src/script_opt/CPP/Inits.cc +++ b/src/script_opt/CPP/Inits.cc @@ -79,17 +79,17 @@ bool CPPCompile::IsSimpleInitExpr(const ExprPtr& e) const return true; case EXPR_RECORD_COERCE: - { // look for coercion of empty record - auto op = e->GetOp1(); + { // look for coercion of empty record + auto op = e->GetOp1(); - if ( op->Tag() != EXPR_RECORD_CONSTRUCTOR ) - return false; + if ( op->Tag() != EXPR_RECORD_CONSTRUCTOR ) + return false; - auto rc = static_cast(op.get()); - const auto& exprs = rc->Op()->AsListExpr()->Exprs(); + auto rc = static_cast(op.get()); + const auto& exprs = rc->Op()->AsListExpr()->Exprs(); - return exprs.length() == 0; - } + return exprs.length() == 0; + } default: return false; @@ -235,16 +235,16 @@ void CPPCompile::GenPreInit(const Type* t) break; case TYPE_RECORD: - { - string name; + { + string name; - if ( t->GetName() != "" ) - name = string("\"") + t->GetName() + string("\""); - else - name = "nullptr"; + if ( t->GetName() != "" ) + name = string("\"") + t->GetName() + string("\""); + else + name = "nullptr"; - pre_init = string("get_record_type__CPP(") + name + ")"; - } + pre_init = string("get_record_type__CPP(") + name + ")"; + } break; case TYPE_LIST: diff --git a/src/script_opt/CPP/RuntimeVec.cc b/src/script_opt/CPP/RuntimeVec.cc index 84a07c816d..3b8eff9c1f 100644 --- a/src/script_opt/CPP/RuntimeVec.cc +++ b/src/script_opt/CPP/RuntimeVec.cc @@ -66,16 +66,16 @@ static VectorTypePtr base_vector_type__CPP(const VectorTypePtr& vt) switch ( vt->Yield()->InternalType() ) \ { \ case TYPE_INTERNAL_INT: \ - { \ - VEC_OP1_KERNEL(AsInt, IntVal, op) \ - break; \ - } \ + { \ + VEC_OP1_KERNEL(AsInt, IntVal, op) \ + break; \ + } \ \ case TYPE_INTERNAL_UNSIGNED: \ - { \ - VEC_OP1_KERNEL(AsCount, CountVal, op) \ - break; \ - } \ + { \ + VEC_OP1_KERNEL(AsCount, CountVal, op) \ + break; \ + } \ \ double_kernel \ \ @@ -126,19 +126,19 @@ VEC_OP1(comp, ~, ) switch ( vt->Yield()->InternalType() ) \ { \ case TYPE_INTERNAL_INT: \ - { \ - if ( vt->Yield()->Tag() == TYPE_BOOL ) \ - VEC_OP2_KERNEL(AsBool, BoolVal, op) \ - else \ - VEC_OP2_KERNEL(AsInt, IntVal, op) \ - break; \ - } \ + { \ + if ( vt->Yield()->Tag() == TYPE_BOOL ) \ + VEC_OP2_KERNEL(AsBool, BoolVal, op) \ + else \ + VEC_OP2_KERNEL(AsInt, IntVal, op) \ + break; \ + } \ \ case TYPE_INTERNAL_UNSIGNED: \ - { \ - VEC_OP2_KERNEL(AsCount, CountVal, op) \ - break; \ - } \ + { \ + VEC_OP2_KERNEL(AsCount, CountVal, op) \ + break; \ + } \ \ double_kernel \ \ @@ -184,22 +184,22 @@ VEC_OP2(oror, ||, ) switch ( vt->Yield()->InternalType() ) \ { \ case TYPE_INTERNAL_INT: \ - { \ - VEC_OP2_KERNEL(AsInt, BoolVal, op) \ - break; \ - } \ + { \ + VEC_OP2_KERNEL(AsInt, BoolVal, op) \ + break; \ + } \ \ case TYPE_INTERNAL_UNSIGNED: \ - { \ - VEC_OP2_KERNEL(AsCount, BoolVal, op) \ - break; \ - } \ + { \ + VEC_OP2_KERNEL(AsCount, BoolVal, op) \ + break; \ + } \ \ case TYPE_INTERNAL_DOUBLE: \ - { \ - VEC_OP2_KERNEL(AsDouble, BoolVal, op) \ - break; \ - } \ + { \ + VEC_OP2_KERNEL(AsDouble, BoolVal, op) \ + break; \ + } \ \ default: \ break; \ diff --git a/src/script_opt/CPP/Stmts.cc b/src/script_opt/CPP/Stmts.cc index 33b28faac8..47d8f713a9 100644 --- a/src/script_opt/CPP/Stmts.cc +++ b/src/script_opt/CPP/Stmts.cc @@ -18,15 +18,15 @@ void CPPCompile::GenStmt(const Stmt* s) break; case STMT_LIST: - { - // These always occur in contexts surrounded by {}'s, - // so no need to add them explicitly. - auto sl = s->AsStmtList(); - const auto& stmts = sl->Stmts(); + { + // These always occur in contexts surrounded by {}'s, + // so no need to add them explicitly. + auto sl = s->AsStmtList(); + const auto& stmts = sl->Stmts(); - for ( const auto& stmt : stmts ) - GenStmt(stmt); - } + for ( const auto& stmt : stmts ) + GenStmt(stmt); + } break; case STMT_EXPR: @@ -82,10 +82,10 @@ void CPPCompile::GenStmt(const Stmt* s) break; case STMT_PRINT: - { - auto el = static_cast(s)->ExprList(); - Emit("do_print_stmt({%s});", GenExpr(el, GEN_VAL_PTR)); - } + { + auto el = static_cast(s)->ExprList(); + Emit("do_print_stmt({%s});", GenExpr(el, GEN_VAL_PTR)); + } break; case STMT_FALLTHROUGH: diff --git a/src/script_opt/CPP/Types.cc b/src/script_opt/CPP/Types.cc index 388b32973c..1e04a33206 100644 --- a/src/script_opt/CPP/Types.cc +++ b/src/script_opt/CPP/Types.cc @@ -466,19 +466,19 @@ void CPPCompile::RegisterType(const TypePtr& tp) break; case TYPE_TYPE: - { - const auto& tt = t->AsTypeType()->GetType(); - NoteNonRecordInitDependency(t, tt); - RegisterType(tt); - } + { + const auto& tt = t->AsTypeType()->GetType(); + NoteNonRecordInitDependency(t, tt); + RegisterType(tt); + } break; case TYPE_VECTOR: - { - const auto& yield = t->AsVectorType()->Yield(); - NoteNonRecordInitDependency(t, yield); - RegisterType(yield); - } + { + const auto& yield = t->AsVectorType()->Yield(); + NoteNonRecordInitDependency(t, yield); + RegisterType(yield); + } break; case TYPE_LIST: diff --git a/src/script_opt/Expr.cc b/src/script_opt/Expr.cc index ab4bb4a18d..c87ef21b31 100644 --- a/src/script_opt/Expr.cc +++ b/src/script_opt/Expr.cc @@ -189,28 +189,28 @@ bool Expr::IsReducedConditional(Reducer* c) const return IsReduced(c); case EXPR_IN: + { + auto op1 = GetOp1(); + auto op2 = GetOp2(); + + if ( op1->Tag() != EXPR_NAME && op1->Tag() != EXPR_LIST ) + return NonReduced(this); + + if ( op2->GetType()->Tag() != TYPE_TABLE || ! op2->IsReduced(c) ) + return NonReduced(this); + + if ( op1->Tag() == EXPR_LIST ) { - auto op1 = GetOp1(); - auto op2 = GetOp2(); + auto l1 = op1->AsListExpr(); + auto& l1_e = l1->Exprs(); - if ( op1->Tag() != EXPR_NAME && op1->Tag() != EXPR_LIST ) + if ( l1_e.length() < 1 || l1_e.length() > 2 ) return NonReduced(this); - - if ( op2->GetType()->Tag() != TYPE_TABLE || ! op2->IsReduced(c) ) - return NonReduced(this); - - if ( op1->Tag() == EXPR_LIST ) - { - auto l1 = op1->AsListExpr(); - auto& l1_e = l1->Exprs(); - - if ( l1_e.length() < 1 || l1_e.length() > 2 ) - return NonReduced(this); - } - - return true; } + return true; + } + case EXPR_EQ: case EXPR_NE: case EXPR_LE: @@ -324,41 +324,41 @@ ExprPtr Expr::ReduceToConditional(Reducer* c, StmtPtr& red_stmt) return Reduce(c, red_stmt); case EXPR_IN: + { + // This is complicated because there are lots of forms + // of "in" expressions, and we're only interested in + // those with 1 or 2 indices, into a table. + auto op1 = GetOp1(); + auto op2 = GetOp2(); + + if ( c->Optimizing() ) + return Reduce(c, red_stmt); + + if ( op2->GetType()->Tag() != TYPE_TABLE ) + // Not a table de-reference. + return Reduce(c, red_stmt); + + if ( op1->Tag() == EXPR_LIST ) { - // This is complicated because there are lots of forms - // of "in" expressions, and we're only interested in - // those with 1 or 2 indices, into a table. - auto op1 = GetOp1(); - auto op2 = GetOp2(); + auto l1 = op1->AsListExpr(); + auto& l1_e = l1->Exprs(); - if ( c->Optimizing() ) + if ( l1_e.length() < 1 || l1_e.length() > 2 ) + // Wrong number of indices. return Reduce(c, red_stmt); - - if ( op2->GetType()->Tag() != TYPE_TABLE ) - // Not a table de-reference. - return Reduce(c, red_stmt); - - if ( op1->Tag() == EXPR_LIST ) - { - auto l1 = op1->AsListExpr(); - auto& l1_e = l1->Exprs(); - - if ( l1_e.length() < 1 || l1_e.length() > 2 ) - // Wrong number of indices. - return Reduce(c, red_stmt); - } - - if ( ! op1->IsReduced(c) || ! op2->IsReduced(c) ) - { - auto red2_stmt = ReduceToSingletons(c); - auto res = ReduceToConditional(c, red_stmt); - red_stmt = MergeStmts(red2_stmt, red_stmt); - return res; - } - - return ThisPtr(); } + if ( ! op1->IsReduced(c) || ! op2->IsReduced(c) ) + { + auto red2_stmt = ReduceToSingletons(c); + auto res = ReduceToConditional(c, red_stmt); + red_stmt = MergeStmts(red2_stmt, red_stmt); + return res; + } + + return ThisPtr(); + } + case EXPR_EQ: case EXPR_NE: case EXPR_LE: @@ -1489,10 +1489,10 @@ bool RefExpr::HasReducedOps(Reducer* c) const return op->AsFieldExpr()->Op()->IsReduced(c); case EXPR_INDEX: - { - auto ind = op->AsIndexExpr(); - return ind->Op1()->IsReduced(c) && ind->Op2()->IsReduced(c); - } + { + auto ind = op->AsIndexExpr(); + return ind->Op1()->IsReduced(c) && ind->Op2()->IsReduced(c); + } case EXPR_LIST: return op->IsReduced(c); diff --git a/src/script_opt/GenIDDefs.cc b/src/script_opt/GenIDDefs.cc index ef6fdbe295..440316019d 100644 --- a/src/script_opt/GenIDDefs.cc +++ b/src/script_opt/GenIDDefs.cc @@ -67,140 +67,140 @@ TraversalCode GenIDDefs::PreStmt(const Stmt* s) switch ( s->Tag() ) { case STMT_CATCH_RETURN: - { - auto cr = s->AsCatchReturnStmt(); - auto block = cr->Block(); + { + auto cr = s->AsCatchReturnStmt(); + auto block = cr->Block(); - StartConfluenceBlock(s); - block->Traverse(this); - EndConfluenceBlock(); + StartConfluenceBlock(s); + block->Traverse(this); + EndConfluenceBlock(); - auto retvar = cr->RetVar(); - if ( retvar ) - TrackID(retvar->Id()); + auto retvar = cr->RetVar(); + if ( retvar ) + TrackID(retvar->Id()); - return TC_ABORTSTMT; - } + return TC_ABORTSTMT; + } case STMT_IF: - { - auto i = s->AsIfStmt(); - auto cond = i->StmtExpr(); - auto t_branch = i->TrueBranch(); - auto f_branch = i->FalseBranch(); + { + auto i = s->AsIfStmt(); + auto cond = i->StmtExpr(); + auto t_branch = i->TrueBranch(); + auto f_branch = i->FalseBranch(); - cond->Traverse(this); + cond->Traverse(this); - StartConfluenceBlock(s); + StartConfluenceBlock(s); - t_branch->Traverse(this); - if ( ! t_branch->NoFlowAfter(false) ) - BranchBeyond(curr_stmt, s, true); + t_branch->Traverse(this); + if ( ! t_branch->NoFlowAfter(false) ) + BranchBeyond(curr_stmt, s, true); - f_branch->Traverse(this); - if ( ! f_branch->NoFlowAfter(false) ) - BranchBeyond(curr_stmt, s, true); + f_branch->Traverse(this); + if ( ! f_branch->NoFlowAfter(false) ) + BranchBeyond(curr_stmt, s, true); - EndConfluenceBlock(true); + EndConfluenceBlock(true); - return TC_ABORTSTMT; - } + return TC_ABORTSTMT; + } case STMT_SWITCH: + { + auto sw = s->AsSwitchStmt(); + auto e = sw->StmtExpr(); + + e->Traverse(this); + + StartConfluenceBlock(sw); + + for ( const auto& c : *sw->Cases() ) { - auto sw = s->AsSwitchStmt(); - auto e = sw->StmtExpr(); + auto body = c->Body(); - e->Traverse(this); + auto exprs = c->ExprCases(); + if ( exprs ) + exprs->Traverse(this); - StartConfluenceBlock(sw); - - for ( const auto& c : *sw->Cases() ) + auto type_ids = c->TypeCases(); + if ( type_ids ) { - auto body = c->Body(); - - auto exprs = c->ExprCases(); - if ( exprs ) - exprs->Traverse(this); - - auto type_ids = c->TypeCases(); - if ( type_ids ) - { - for ( const auto& id : *type_ids ) - if ( id->Name() ) - TrackID(id); - } - - body->Traverse(this); + for ( const auto& id : *type_ids ) + if ( id->Name() ) + TrackID(id); } - EndConfluenceBlock(sw->HasDefault()); - - return TC_ABORTSTMT; + body->Traverse(this); } + EndConfluenceBlock(sw->HasDefault()); + + return TC_ABORTSTMT; + } + case STMT_FOR: - { - auto f = s->AsForStmt(); + { + auto f = s->AsForStmt(); - auto ids = f->LoopVars(); - auto e = f->LoopExpr(); - auto body = f->LoopBody(); - auto val_var = f->ValueVar(); + auto ids = f->LoopVars(); + auto e = f->LoopExpr(); + auto body = f->LoopBody(); + auto val_var = f->ValueVar(); - e->Traverse(this); + e->Traverse(this); - for ( const auto& id : *ids ) - TrackID(id); + for ( const auto& id : *ids ) + TrackID(id); - if ( val_var ) - TrackID(val_var); + if ( val_var ) + TrackID(val_var); - StartConfluenceBlock(s); - body->Traverse(this); + StartConfluenceBlock(s); + body->Traverse(this); - if ( ! body->NoFlowAfter(false) ) - BranchBackTo(curr_stmt, s, true); + if ( ! body->NoFlowAfter(false) ) + BranchBackTo(curr_stmt, s, true); - EndConfluenceBlock(); + EndConfluenceBlock(); - return TC_ABORTSTMT; - } + return TC_ABORTSTMT; + } case STMT_WHILE: - { - auto w = s->AsWhileStmt(); + { + auto w = s->AsWhileStmt(); - StartConfluenceBlock(s); + StartConfluenceBlock(s); - auto cond_pred_stmt = w->CondPredStmt(); - if ( cond_pred_stmt ) - cond_pred_stmt->Traverse(this); + auto cond_pred_stmt = w->CondPredStmt(); + if ( cond_pred_stmt ) + cond_pred_stmt->Traverse(this); - // Important to traverse the condition in its version - // interpreted as a statement, so that when evaluating - // its variable usage, that's done in the context of - // *after* cond_pred_stmt executes, rather than as - // part of that execution. - auto cond_stmt = w->ConditionAsStmt(); - cond_stmt->Traverse(this); + // Important to traverse the condition in its version + // interpreted as a statement, so that when evaluating + // its variable usage, that's done in the context of + // *after* cond_pred_stmt executes, rather than as + // part of that execution. + auto cond_stmt = w->ConditionAsStmt(); + cond_stmt->Traverse(this); - auto body = w->Body(); - body->Traverse(this); + auto body = w->Body(); + body->Traverse(this); - if ( ! body->NoFlowAfter(false) ) - BranchBackTo(curr_stmt, s, true); + if ( ! body->NoFlowAfter(false) ) + BranchBackTo(curr_stmt, s, true); - EndConfluenceBlock(); + EndConfluenceBlock(); - return TC_ABORTSTMT; - } + return TC_ABORTSTMT; + } case STMT_WHEN: - { - // ### punt on these for now, need to reflect on bindings. - return TC_ABORTSTMT; - } + { + // ### punt on these for now, need to reflect on bindings. + return TC_ABORTSTMT; + } default: return TC_CONTINUE; @@ -212,22 +212,22 @@ TraversalCode GenIDDefs::PostStmt(const Stmt* s) switch ( s->Tag() ) { case STMT_INIT: + { + auto init = s->AsInitStmt(); + auto& inits = init->Inits(); + + for ( const auto& id : inits ) { - auto init = s->AsInitStmt(); - auto& inits = init->Inits(); + auto id_t = id->GetType(); - for ( const auto& id : inits ) - { - auto id_t = id->GetType(); - - // Only aggregates get initialized. - if ( zeek::IsAggr(id->GetType()->Tag()) ) - TrackID(id); - } - - break; + // Only aggregates get initialized. + if ( zeek::IsAggr(id->GetType()->Tag()) ) + TrackID(id); } + break; + } + case STMT_RETURN: ReturnAt(s); break; @@ -237,21 +237,21 @@ TraversalCode GenIDDefs::PostStmt(const Stmt* s) break; case STMT_BREAK: + { + auto target = FindBreakTarget(); + + if ( target ) + BranchBeyond(s, target, false); + + else { - auto target = FindBreakTarget(); - - if ( target ) - BranchBeyond(s, target, false); - - else - { - ASSERT(func_flavor == FUNC_FLAVOR_HOOK); - ReturnAt(s); - } - - break; + ASSERT(func_flavor == FUNC_FLAVOR_HOOK); + ReturnAt(s); } + break; + } + case STMT_FALLTHROUGH: // No need to do anything, the work all occurs // with NoFlowAfter. @@ -275,29 +275,29 @@ TraversalCode GenIDDefs::PreExpr(const Expr* e) break; case EXPR_ASSIGN: + { + auto lhs = e->GetOp1(); + auto op2 = e->GetOp2(); + + if ( lhs->Tag() == EXPR_LIST && op2->GetType()->Tag() != TYPE_ANY ) { - auto lhs = e->GetOp1(); - auto op2 = e->GetOp2(); - - if ( lhs->Tag() == EXPR_LIST && op2->GetType()->Tag() != TYPE_ANY ) - { - // This combination occurs only for assignments used - // to initialize table entries. Treat it as references - // to both the lhs and the rhs, not as an assignment. - return TC_CONTINUE; - } - - op2->Traverse(this); - - if ( ! CheckLHS(lhs, op2) ) - // Not a simple assignment (or group of assignments), - // so analyze the accesses to check for use of - // possibly undefined values. - lhs->Traverse(this); - - return TC_ABORTSTMT; + // This combination occurs only for assignments used + // to initialize table entries. Treat it as references + // to both the lhs and the rhs, not as an assignment. + return TC_CONTINUE; } + op2->Traverse(this); + + if ( ! CheckLHS(lhs, op2) ) + // Not a simple assignment (or group of assignments), + // so analyze the accesses to check for use of + // possibly undefined values. + lhs->Traverse(this); + + return TC_ABORTSTMT; + } + case EXPR_COND: // Special hack. We turn off checking for usage issues // inside conditionals. This is because we use them heavily @@ -314,17 +314,17 @@ TraversalCode GenIDDefs::PreExpr(const Expr* e) return TC_ABORTSTMT; case EXPR_LAMBDA: - { - auto l = static_cast(e); - const auto& ids = l->OuterIDs(); + { + auto l = static_cast(e); + const auto& ids = l->OuterIDs(); - for ( auto& id : ids ) - CheckVarUsage(e, id); + for ( auto& id : ids ) + CheckVarUsage(e, id); - // Don't descend into the lambda body - we'll analyze and - // optimize it separately, as its own function. - return TC_ABORTSTMT; - } + // Don't descend into the lambda body - we'll analyze and + // optimize it separately, as its own function. + return TC_ABORTSTMT; + } default: break; @@ -360,29 +360,29 @@ bool GenIDDefs::CheckLHS(const ExprPtr& lhs, const ExprPtr& rhs) return CheckLHS(lhs->GetOp1(), rhs); case EXPR_NAME: - { - auto n = lhs->AsNameExpr(); - TrackID(n->Id(), rhs); - return true; - } + { + auto n = lhs->AsNameExpr(); + TrackID(n->Id(), rhs); + return true; + } case EXPR_LIST: - { // look for [a, b, c] = any_val - auto l = lhs->AsListExpr(); - for ( const auto& expr : l->Exprs() ) - { - if ( expr->Tag() != EXPR_NAME ) - // This will happen for table initializers, - // for example. - return false; + { // look for [a, b, c] = any_val + auto l = lhs->AsListExpr(); + for ( const auto& expr : l->Exprs() ) + { + if ( expr->Tag() != EXPR_NAME ) + // This will happen for table initializers, + // for example. + return false; - auto n = expr->AsNameExpr(); - TrackID(n->Id()); - } - - return true; + auto n = expr->AsNameExpr(); + TrackID(n->Id()); } + return true; + } + case EXPR_FIELD: // If we want to track record field initializations, // we'd handle that here. diff --git a/src/script_opt/ProfileFunc.cc b/src/script_opt/ProfileFunc.cc index eae018bac2..da6802ff99 100644 --- a/src/script_opt/ProfileFunc.cc +++ b/src/script_opt/ProfileFunc.cc @@ -129,49 +129,49 @@ TraversalCode ProfileFunc::PreStmt(const Stmt* s) break; case STMT_FOR: - { - auto sf = s->AsForStmt(); - auto loop_vars = sf->LoopVars(); - auto value_var = sf->ValueVar(); + { + auto sf = s->AsForStmt(); + auto loop_vars = sf->LoopVars(); + auto value_var = sf->ValueVar(); - for ( auto id : *loop_vars ) - locals.insert(id); + for ( auto id : *loop_vars ) + locals.insert(id); - if ( value_var ) - locals.insert(value_var.get()); - } + if ( value_var ) + locals.insert(value_var.get()); + } break; case STMT_SWITCH: + { + // If this is a type-case switch statement, then find the + // identifiers created so we can add them to our list of + // locals. Ideally this wouldn't be necessary since *surely* + // if one bothers to define such an identifier then it'll be + // subsequently used, and we'll pick up the local that way ... + // but if for some reason it's not, then we would have an + // incomplete list of locals that need to be tracked. + + auto sw = s->AsSwitchStmt(); + bool is_type_switch = false; + + for ( auto& c : *sw->Cases() ) { - // If this is a type-case switch statement, then find the - // identifiers created so we can add them to our list of - // locals. Ideally this wouldn't be necessary since *surely* - // if one bothers to define such an identifier then it'll be - // subsequently used, and we'll pick up the local that way ... - // but if for some reason it's not, then we would have an - // incomplete list of locals that need to be tracked. - - auto sw = s->AsSwitchStmt(); - bool is_type_switch = false; - - for ( auto& c : *sw->Cases() ) + auto idl = c->TypeCases(); + if ( idl ) { - auto idl = c->TypeCases(); - if ( idl ) - { - for ( auto id : *idl ) - locals.insert(id); + for ( auto id : *idl ) + locals.insert(id); - is_type_switch = true; - } + is_type_switch = true; } - - if ( is_type_switch ) - type_switches.insert(sw); - else - expr_switches.insert(sw); } + + if ( is_type_switch ) + type_switches.insert(sw); + else + expr_switches.insert(sw); + } break; default: @@ -194,46 +194,46 @@ TraversalCode ProfileFunc::PreExpr(const Expr* e) break; case EXPR_NAME: + { + auto n = e->AsNameExpr(); + auto id = n->Id(); + + if ( id->IsGlobal() ) { - auto n = e->AsNameExpr(); - auto id = n->Id(); + globals.insert(id); + all_globals.insert(id); - if ( id->IsGlobal() ) - { - globals.insert(id); - all_globals.insert(id); - - const auto& t = id->GetType(); - if ( t->Tag() == TYPE_FUNC && t->AsFuncType()->Flavor() == FUNC_FLAVOR_EVENT ) - events.insert(id->Name()); - } - - else - { - // This is a tad ugly. Unfortunately due to the - // weird way that Zeek function *declarations* work, - // there's no reliable way to get the list of - // parameters for a function *definition*, since - // they can have different names than what's present - // in the declaration. So we identify them directly, - // by knowing that they come at the beginning of the - // frame ... and being careful to avoid misconfusing - // a lambda capture with a low frame offset as a - // parameter. - if ( captures.count(id) == 0 && id->Offset() < num_params ) - params.insert(id); - - locals.insert(id); - } - - // Turns out that NameExpr's can be constructed using a - // different Type* than that of the identifier itself, - // so be sure we track the latter too. - TrackType(id->GetType()); - - break; + const auto& t = id->GetType(); + if ( t->Tag() == TYPE_FUNC && t->AsFuncType()->Flavor() == FUNC_FLAVOR_EVENT ) + events.insert(id->Name()); } + else + { + // This is a tad ugly. Unfortunately due to the + // weird way that Zeek function *declarations* work, + // there's no reliable way to get the list of + // parameters for a function *definition*, since + // they can have different names than what's present + // in the declaration. So we identify them directly, + // by knowing that they come at the beginning of the + // frame ... and being careful to avoid misconfusing + // a lambda capture with a low frame offset as a + // parameter. + if ( captures.count(id) == 0 && id->Offset() < num_params ) + params.insert(id); + + locals.insert(id); + } + + // Turns out that NameExpr's can be constructed using a + // different Type* than that of the identifier itself, + // so be sure we track the latter too. + TrackType(id->GetType()); + + break; + } + case EXPR_FIELD: if ( abs_rec_fields ) { @@ -265,130 +265,130 @@ TraversalCode ProfileFunc::PreExpr(const Expr* e) case EXPR_ADD_TO: case EXPR_REMOVE_FROM: case EXPR_ASSIGN: + { + if ( e->GetOp1()->Tag() == EXPR_REF ) { - if ( e->GetOp1()->Tag() == EXPR_REF ) - { - auto lhs = e->GetOp1()->GetOp1(); - if ( lhs->Tag() == EXPR_NAME ) - TrackAssignment(lhs->AsNameExpr()->Id()); - } - // else this isn't a direct assignment. - break; + auto lhs = e->GetOp1()->GetOp1(); + if ( lhs->Tag() == EXPR_NAME ) + TrackAssignment(lhs->AsNameExpr()->Id()); } + // else this isn't a direct assignment. + break; + } case EXPR_CALL: + { + auto c = e->AsCallExpr(); + auto f = c->Func(); + + if ( f->Tag() != EXPR_NAME ) { - auto c = e->AsCallExpr(); - auto f = c->Func(); + does_indirect_calls = true; + return TC_CONTINUE; + } - if ( f->Tag() != EXPR_NAME ) + auto n = f->AsNameExpr(); + auto func = n->Id(); + + if ( ! func->IsGlobal() ) + { + does_indirect_calls = true; + return TC_CONTINUE; + } + + all_globals.insert(func); + + auto func_v = func->GetVal(); + if ( func_v ) + { + auto func_vf = func_v->AsFunc(); + + if ( func_vf->GetKind() == Func::SCRIPT_FUNC ) { - does_indirect_calls = true; - return TC_CONTINUE; - } + auto bf = static_cast(func_vf); + script_calls.insert(bf); - auto n = f->AsNameExpr(); - auto func = n->Id(); - - if ( ! func->IsGlobal() ) - { - does_indirect_calls = true; - return TC_CONTINUE; - } - - all_globals.insert(func); - - auto func_v = func->GetVal(); - if ( func_v ) - { - auto func_vf = func_v->AsFunc(); - - if ( func_vf->GetKind() == Func::SCRIPT_FUNC ) - { - auto bf = static_cast(func_vf); - script_calls.insert(bf); - - if ( in_when ) - when_calls.insert(bf); - } - else - BiF_globals.insert(func); + if ( in_when ) + when_calls.insert(bf); } else - { - // We could complain, but for now we don't, because - // if we're invoked prior to full Zeek initialization, - // the value might indeed not there yet. - // printf("no function value for global %s\n", func->Name()); - } - - // Recurse into the arguments. - auto args = c->Args(); - args->Traverse(this); - - // Do the following explicitly, since we won't be recursing - // into the LHS global. - - // Note that the type of the expression and the type of the - // function can actually be *different* due to the NameExpr - // being constructed based on a forward reference and then - // the global getting a different (constructed) type when - // the function is actually declared. Geez. So hedge our - // bets. - TrackType(n->GetType()); - TrackType(func->GetType()); - - TrackID(func); - - return TC_ABORTSTMT; + BiF_globals.insert(func); } + else + { + // We could complain, but for now we don't, because + // if we're invoked prior to full Zeek initialization, + // the value might indeed not there yet. + // printf("no function value for global %s\n", func->Name()); + } + + // Recurse into the arguments. + auto args = c->Args(); + args->Traverse(this); + + // Do the following explicitly, since we won't be recursing + // into the LHS global. + + // Note that the type of the expression and the type of the + // function can actually be *different* due to the NameExpr + // being constructed based on a forward reference and then + // the global getting a different (constructed) type when + // the function is actually declared. Geez. So hedge our + // bets. + TrackType(n->GetType()); + TrackType(func->GetType()); + + TrackID(func); + + return TC_ABORTSTMT; + } case EXPR_EVENT: - { - auto ev = e->AsEventExpr()->Name(); - events.insert(ev); - addl_hashes.push_back(p_hash(ev)); - } + { + auto ev = e->AsEventExpr()->Name(); + events.insert(ev); + addl_hashes.push_back(p_hash(ev)); + } break; case EXPR_LAMBDA: + { + auto l = e->AsLambdaExpr(); + lambdas.push_back(l); + + for ( const auto& i : l->OuterIDs() ) { - auto l = e->AsLambdaExpr(); - lambdas.push_back(l); + locals.insert(i); + TrackID(i); - for ( const auto& i : l->OuterIDs() ) - { - locals.insert(i); - TrackID(i); - - // See above re EXPR_NAME regarding the following - // logic. - if ( captures.count(i) == 0 && i->Offset() < num_params ) - params.insert(i); - } - - // Avoid recursing into the body. - return TC_ABORTSTMT; + // See above re EXPR_NAME regarding the following + // logic. + if ( captures.count(i) == 0 && i->Offset() < num_params ) + params.insert(i); } + // Avoid recursing into the body. + return TC_ABORTSTMT; + } + case EXPR_SET_CONSTRUCTOR: - { - auto sc = static_cast(e); - const auto& attrs = sc->GetAttrs(); + { + auto sc = static_cast(e); + const auto& attrs = sc->GetAttrs(); - if ( attrs ) - constructor_attrs.insert(attrs.get()); - } + if ( attrs ) + constructor_attrs.insert(attrs.get()); + } break; case EXPR_TABLE_CONSTRUCTOR: - { - auto tc = static_cast(e); - const auto& attrs = tc->GetAttrs(); + { + auto tc = static_cast(e); + const auto& attrs = tc->GetAttrs(); - if ( attrs ) - constructor_attrs.insert(attrs.get()); - } + if ( attrs ) + constructor_attrs.insert(attrs.get()); + } break; default: @@ -560,46 +560,46 @@ void ProfileFuncs::TraverseValue(const ValPtr& v) break; case TYPE_RECORD: - { - auto r = cast_intrusive(v); - auto n = r->NumFields(); + { + auto r = cast_intrusive(v); + auto n = r->NumFields(); - for ( auto i = 0u; i < n; ++i ) - TraverseValue(r->GetField(i)); - } + for ( auto i = 0u; i < n; ++i ) + TraverseValue(r->GetField(i)); + } break; case TYPE_TABLE: - { - auto tv = cast_intrusive(v); - auto tv_map = tv->ToMap(); + { + auto tv = cast_intrusive(v); + auto tv_map = tv->ToMap(); - for ( auto& tv_i : tv_map ) - { - TraverseValue(tv_i.first); - TraverseValue(tv_i.second); - } + for ( auto& tv_i : tv_map ) + { + TraverseValue(tv_i.first); + TraverseValue(tv_i.second); } + } break; case TYPE_LIST: - { - auto lv = cast_intrusive(v); - auto n = lv->Length(); + { + auto lv = cast_intrusive(v); + auto n = lv->Length(); - for ( auto i = 0; i < n; ++i ) - TraverseValue(lv->Idx(i)); - } + for ( auto i = 0; i < n; ++i ) + TraverseValue(lv->Idx(i)); + } break; case TYPE_VECTOR: - { - auto vv = cast_intrusive(v); - auto n = vv->Size(); + { + auto vv = cast_intrusive(v); + auto n = vv->Size(); - for ( auto i = 0u; i < n; ++i ) - TraverseValue(vv->ValAt(i)); - } + for ( auto i = 0u; i < n; ++i ) + TraverseValue(vv->ValAt(i)); + } break; case TYPE_TYPE: @@ -759,82 +759,82 @@ p_hash_type ProfileFuncs::HashType(const Type* t) break; case TYPE_RECORD: + { + const auto& ft = t->AsRecordType(); + auto n = ft->NumFields(); + auto orig_n = ft->NumOrigFields(); + + h = merge_p_hashes(h, p_hash("record")); + + if ( full_record_hashes ) + h = merge_p_hashes(h, p_hash(n)); + else + h = merge_p_hashes(h, p_hash(orig_n)); + + for ( auto i = 0; i < n; ++i ) { - const auto& ft = t->AsRecordType(); - auto n = ft->NumFields(); - auto orig_n = ft->NumOrigFields(); + bool do_hash = full_record_hashes; + if ( ! do_hash ) + do_hash = (i < orig_n); - h = merge_p_hashes(h, p_hash("record")); + const auto& f = ft->FieldDecl(i); + auto type_h = HashType(f->type); - if ( full_record_hashes ) - h = merge_p_hashes(h, p_hash(n)); - else - h = merge_p_hashes(h, p_hash(orig_n)); - - for ( auto i = 0; i < n; ++i ) + if ( do_hash ) { - bool do_hash = full_record_hashes; - if ( ! do_hash ) - do_hash = (i < orig_n); - - const auto& f = ft->FieldDecl(i); - auto type_h = HashType(f->type); - - if ( do_hash ) - { - h = merge_p_hashes(h, p_hash(f->id)); - h = merge_p_hashes(h, type_h); - } - h = merge_p_hashes(h, p_hash(f->id)); - h = merge_p_hashes(h, HashType(f->type)); + h = merge_p_hashes(h, type_h); + } - // We don't hash the field name, as in some contexts - // those are ignored. + h = merge_p_hashes(h, p_hash(f->id)); + h = merge_p_hashes(h, HashType(f->type)); - if ( f->attrs ) - { - if ( do_hash ) - h = merge_p_hashes(h, HashAttrs(f->attrs)); - AnalyzeAttrs(f->attrs.get()); - } + // We don't hash the field name, as in some contexts + // those are ignored. + + if ( f->attrs ) + { + if ( do_hash ) + h = merge_p_hashes(h, HashAttrs(f->attrs)); + AnalyzeAttrs(f->attrs.get()); } } + } break; case TYPE_TABLE: - { - auto tbl = t->AsTableType(); - h = merge_p_hashes(h, p_hash("table")); - h = merge_p_hashes(h, p_hash("indices")); - h = merge_p_hashes(h, HashType(tbl->GetIndices())); - h = merge_p_hashes(h, p_hash("tbl-yield")); - h = merge_p_hashes(h, HashType(tbl->Yield())); - } + { + auto tbl = t->AsTableType(); + h = merge_p_hashes(h, p_hash("table")); + h = merge_p_hashes(h, p_hash("indices")); + h = merge_p_hashes(h, HashType(tbl->GetIndices())); + h = merge_p_hashes(h, p_hash("tbl-yield")); + h = merge_p_hashes(h, HashType(tbl->Yield())); + } break; case TYPE_FUNC: - { - auto ft = t->AsFuncType(); - auto flv = ft->FlavorString(); - h = merge_p_hashes(h, p_hash(flv)); - h = merge_p_hashes(h, p_hash("params")); - h = merge_p_hashes(h, HashType(ft->Params())); - h = merge_p_hashes(h, p_hash("func-yield")); - h = merge_p_hashes(h, HashType(ft->Yield())); - } + { + auto ft = t->AsFuncType(); + auto flv = ft->FlavorString(); + h = merge_p_hashes(h, p_hash(flv)); + h = merge_p_hashes(h, p_hash("params")); + h = merge_p_hashes(h, HashType(ft->Params())); + h = merge_p_hashes(h, p_hash("func-yield")); + h = merge_p_hashes(h, HashType(ft->Yield())); + } break; case TYPE_LIST: - { - auto& tl = t->AsTypeList()->GetTypes(); + { + auto& tl = t->AsTypeList()->GetTypes(); - h = merge_p_hashes(h, p_hash("list")); - h = merge_p_hashes(h, p_hash(tl.size())); + h = merge_p_hashes(h, p_hash("list")); + h = merge_p_hashes(h, p_hash(tl.size())); - for ( const auto& tl_i : tl ) - h = merge_p_hashes(h, HashType(tl_i)); - } + for ( const auto& tl_i : tl ) + h = merge_p_hashes(h, HashType(tl_i)); + } break; case TYPE_VECTOR: diff --git a/src/script_opt/Reduce.cc b/src/script_opt/Reduce.cc index aded187fe4..63ad87f5af 100644 --- a/src/script_opt/Reduce.cc +++ b/src/script_opt/Reduce.cc @@ -272,81 +272,81 @@ bool Reducer::SameExpr(const Expr* e1, const Expr* e2) reporter->InternalError("Unexpected tag in Reducer::SameExpr"); case EXPR_ANY_INDEX: - { - auto a1 = e1->AsAnyIndexExpr(); - auto a2 = e2->AsAnyIndexExpr(); + { + auto a1 = e1->AsAnyIndexExpr(); + auto a2 = e2->AsAnyIndexExpr(); - if ( a1->Index() != a2->Index() ) - return false; + if ( a1->Index() != a2->Index() ) + return false; - return SameOp(a1->GetOp1(), a2->GetOp1()); - } + return SameOp(a1->GetOp1(), a2->GetOp1()); + } case EXPR_FIELD: - { - auto f1 = e1->AsFieldExpr(); - auto f2 = e2->AsFieldExpr(); + { + auto f1 = e1->AsFieldExpr(); + auto f2 = e2->AsFieldExpr(); - if ( f1->Field() != f2->Field() ) - return false; + if ( f1->Field() != f2->Field() ) + return false; - return SameOp(f1->GetOp1(), f2->GetOp1()); - } + return SameOp(f1->GetOp1(), f2->GetOp1()); + } case EXPR_HAS_FIELD: - { - auto f1 = e1->AsHasFieldExpr(); - auto f2 = e2->AsHasFieldExpr(); + { + auto f1 = e1->AsHasFieldExpr(); + auto f2 = e2->AsHasFieldExpr(); - if ( f1->Field() != f2->Field() ) - return false; + if ( f1->Field() != f2->Field() ) + return false; - return SameOp(f1->GetOp1(), f2->GetOp1()); - } + return SameOp(f1->GetOp1(), f2->GetOp1()); + } case EXPR_LIST: - { - auto l1 = e1->AsListExpr()->Exprs(); - auto l2 = e2->AsListExpr()->Exprs(); + { + auto l1 = e1->AsListExpr()->Exprs(); + auto l2 = e2->AsListExpr()->Exprs(); - ASSERT(l1.length() == l2.length()); + ASSERT(l1.length() == l2.length()); - for ( int i = 0; i < l1.length(); ++i ) - if ( ! SameExpr(l1[i], l2[i]) ) - return false; + for ( int i = 0; i < l1.length(); ++i ) + if ( ! SameExpr(l1[i], l2[i]) ) + return false; - return true; - } + return true; + } case EXPR_CALL: - { - auto c1 = e1->AsCallExpr(); - auto c2 = e2->AsCallExpr(); - auto f1 = c1->Func(); - auto f2 = c2->Func(); + { + auto c1 = e1->AsCallExpr(); + auto c2 = e2->AsCallExpr(); + auto f1 = c1->Func(); + auto f2 = c2->Func(); - if ( f1 != f2 ) - return false; + if ( f1 != f2 ) + return false; - if ( ! f1->IsPure() ) - return false; + if ( ! f1->IsPure() ) + return false; - return SameExpr(c1->Args(), c2->Args()); - } + return SameExpr(c1->Args(), c2->Args()); + } case EXPR_LAMBDA: return false; case EXPR_IS: - { - if ( ! SameOp(e1->GetOp1(), e2->GetOp1()) ) - return false; + { + if ( ! SameOp(e1->GetOp1(), e2->GetOp1()) ) + return false; - auto i1 = e1->AsIsExpr(); - auto i2 = e2->AsIsExpr(); + auto i1 = e1->AsIsExpr(); + auto i2 = e2->AsIsExpr(); - return same_type(i1->TestType(), i2->TestType()); - } + return same_type(i1->TestType(), i2->TestType()); + } default: if ( ! e1->GetOp1() ) @@ -865,59 +865,59 @@ TraversalCode CSE_ValidityChecker::PreExpr(const Expr* e) switch ( t ) { case EXPR_ASSIGN: + { + auto lhs_ref = e->GetOp1()->AsRefExprPtr(); + auto lhs = lhs_ref->GetOp1()->AsNameExpr(); + + if ( CheckID(ids, lhs->Id(), false) ) { - auto lhs_ref = e->GetOp1()->AsRefExprPtr(); - auto lhs = lhs_ref->GetOp1()->AsNameExpr(); - - if ( CheckID(ids, lhs->Id(), false) ) - { - is_valid = false; - return TC_ABORTALL; - } - - // Note, we don't use CheckAggrMod() because this - // is a plain assignment. It might be changing a variable's - // binding to an aggregate, but it's not changing the - // aggregate itself. + is_valid = false; + return TC_ABORTALL; } + + // Note, we don't use CheckAggrMod() because this + // is a plain assignment. It might be changing a variable's + // binding to an aggregate, but it's not changing the + // aggregate itself. + } break; case EXPR_INDEX_ASSIGN: - { - auto lhs_aggr = e->GetOp1(); - auto lhs_aggr_id = lhs_aggr->AsNameExpr()->Id(); + { + auto lhs_aggr = e->GetOp1(); + auto lhs_aggr_id = lhs_aggr->AsNameExpr()->Id(); - if ( CheckID(ids, lhs_aggr_id, true) || CheckAggrMod(ids, e) ) - { - is_valid = false; - return TC_ABORTALL; - } + if ( CheckID(ids, lhs_aggr_id, true) || CheckAggrMod(ids, e) ) + { + is_valid = false; + return TC_ABORTALL; } + } break; case EXPR_FIELD_LHS_ASSIGN: + { + auto lhs = e->GetOp1(); + auto lhs_aggr_id = lhs->AsNameExpr()->Id(); + auto lhs_field = e->AsFieldLHSAssignExpr()->Field(); + + if ( lhs_field == field && same_type(lhs_aggr_id->GetType(), field_type) ) { - auto lhs = e->GetOp1(); - auto lhs_aggr_id = lhs->AsNameExpr()->Id(); - auto lhs_field = e->AsFieldLHSAssignExpr()->Field(); - - if ( lhs_field == field && same_type(lhs_aggr_id->GetType(), field_type) ) - { - // Potential assignment to the same field as for - // our expression of interest. Even if the - // identifier involved is not one we have our eye - // on, due to aggregate aliasing this could be - // altering the value of our expression, so bail. - is_valid = false; - return TC_ABORTALL; - } - - if ( CheckID(ids, lhs_aggr_id, true) || CheckAggrMod(ids, e) ) - { - is_valid = false; - return TC_ABORTALL; - } + // Potential assignment to the same field as for + // our expression of interest. Even if the + // identifier involved is not one we have our eye + // on, due to aggregate aliasing this could be + // altering the value of our expression, so bail. + is_valid = false; + return TC_ABORTALL; } + + if ( CheckID(ids, lhs_aggr_id, true) || CheckAggrMod(ids, e) ) + { + is_valid = false; + return TC_ABORTALL; + } + } break; case EXPR_APPEND_TO: @@ -931,14 +931,14 @@ TraversalCode CSE_ValidityChecker::PreExpr(const Expr* e) break; case EXPR_CALL: - { - for ( auto i : ids ) - if ( i->IsGlobal() || IsAggr(i->GetType()) ) - { - is_valid = false; - return TC_ABORTALL; - } - } + { + for ( auto i : ids ) + if ( i->IsGlobal() || IsAggr(i->GetType()) ) + { + is_valid = false; + return TC_ABORTALL; + } + } break; default: diff --git a/src/script_opt/UseDefs.cc b/src/script_opt/UseDefs.cc index 909da1bbe8..de204cc558 100644 --- a/src/script_opt/UseDefs.cc +++ b/src/script_opt/UseDefs.cc @@ -185,40 +185,40 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo switch ( s->Tag() ) { case STMT_LIST: + { + auto sl = s->AsStmtList(); + const auto& stmts = sl->Stmts(); + + for ( int i = stmts.length(); --i >= 0; ) { - auto sl = s->AsStmtList(); - const auto& stmts = sl->Stmts(); + auto s_i = stmts[i]; - for ( int i = stmts.length(); --i >= 0; ) - { - auto s_i = stmts[i]; + const Stmt* succ; - const Stmt* succ; - - if ( i == stmts.length() - 1 ) - { // Very last statement. - succ = succ_stmt; - if ( successor2.find(s) != successor2.end() ) - successor2[s_i] = successor2[s]; - } - else - succ = stmts[i + 1]; - - succ_UDs = PropagateUDs(s_i, succ_UDs, succ, second_pass); + if ( i == stmts.length() - 1 ) + { // Very last statement. + succ = succ_stmt; + if ( successor2.find(s) != successor2.end() ) + successor2[s_i] = successor2[s]; } + else + succ = stmts[i + 1]; - return UseUDs(s, succ_UDs); + succ_UDs = PropagateUDs(s_i, succ_UDs, succ, second_pass); } + return UseUDs(s, succ_UDs); + } + case STMT_CATCH_RETURN: - { - auto cr = s->AsCatchReturnStmt(); - auto block = cr->Block(); + { + auto cr = s->AsCatchReturnStmt(); + auto block = cr->Block(); - auto uds = PropagateUDs(block.get(), succ_UDs, succ_stmt, second_pass); + auto uds = PropagateUDs(block.get(), succ_UDs, succ_stmt, second_pass); - return UseUDs(s, uds); - } + return UseUDs(s, uds); + } case STMT_NULL: case STMT_NEXT: @@ -238,55 +238,55 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo case STMT_ADD: case STMT_DELETE: case STMT_RETURN: - { - auto e = static_cast(s)->StmtExpr(); + { + auto e = static_cast(s)->StmtExpr(); - if ( e ) - return CreateExprUDs(s, e, succ_UDs); - else - return UseUDs(s, succ_UDs); - } + if ( e ) + return CreateExprUDs(s, e, succ_UDs); + else + return UseUDs(s, succ_UDs); + } case STMT_EXPR: - { - auto e = s->AsExprStmt()->StmtExpr(); + { + auto e = s->AsExprStmt()->StmtExpr(); - if ( e->Tag() != EXPR_ASSIGN ) - return CreateExprUDs(s, e, succ_UDs); + if ( e->Tag() != EXPR_ASSIGN ) + return CreateExprUDs(s, e, succ_UDs); - // Change in use-defs as here we have a definition. - auto a = e->AsAssignExpr(); - auto lhs_ref = a->GetOp1(); + // Change in use-defs as here we have a definition. + auto a = e->AsAssignExpr(); + auto lhs_ref = a->GetOp1(); - if ( lhs_ref->Tag() != EXPR_REF ) - // Since we're working on reduced form ... - reporter->InternalError("lhs inconsistency in UseDefs::ExprUDs"); + if ( lhs_ref->Tag() != EXPR_REF ) + // Since we're working on reduced form ... + reporter->InternalError("lhs inconsistency in UseDefs::ExprUDs"); - auto lhs_var = lhs_ref->GetOp1(); - auto lhs_id = lhs_var->AsNameExpr()->Id(); - auto lhs_UDs = RemoveID(lhs_id, succ_UDs); - auto rhs_UDs = ExprUDs(a->GetOp2().get()); - auto uds = UD_Union(lhs_UDs, rhs_UDs); + auto lhs_var = lhs_ref->GetOp1(); + auto lhs_id = lhs_var->AsNameExpr()->Id(); + auto lhs_UDs = RemoveID(lhs_id, succ_UDs); + auto rhs_UDs = ExprUDs(a->GetOp2().get()); + auto uds = UD_Union(lhs_UDs, rhs_UDs); - if ( ! second_pass ) - successor[s] = succ_stmt; + if ( ! second_pass ) + successor[s] = succ_stmt; - return CreateUDs(s, uds); - } + return CreateUDs(s, uds); + } case STMT_IF: - { - auto i = s->AsIfStmt(); - auto cond = i->StmtExpr(); + { + auto i = s->AsIfStmt(); + auto cond = i->StmtExpr(); - auto cond_UDs = ExprUDs(cond); - auto true_UDs = PropagateUDs(i->TrueBranch(), succ_UDs, succ_stmt, second_pass); - auto false_UDs = PropagateUDs(i->FalseBranch(), succ_UDs, succ_stmt, second_pass); + auto cond_UDs = ExprUDs(cond); + auto true_UDs = PropagateUDs(i->TrueBranch(), succ_UDs, succ_stmt, second_pass); + auto false_UDs = PropagateUDs(i->FalseBranch(), succ_UDs, succ_stmt, second_pass); - auto uds = CreateUDs(s, UD_Union(cond_UDs, true_UDs, false_UDs)); + auto uds = CreateUDs(s, UD_Union(cond_UDs, true_UDs, false_UDs)); - return uds; - } + return uds; + } case STMT_INIT: if ( ! second_pass ) @@ -304,112 +304,112 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo return UseUDs(s, succ_UDs); case STMT_SWITCH: + { + auto sw_UDs = std::make_shared(); + + auto sw = s->AsSwitchStmt(); + auto cases = sw->Cases(); + + for ( const auto& c : *cases ) { - auto sw_UDs = std::make_shared(); + auto body = c->Body(); + auto uds = PropagateUDs(body, succ_UDs, succ_stmt, second_pass); - auto sw = s->AsSwitchStmt(); - auto cases = sw->Cases(); - - for ( const auto& c : *cases ) + auto exprs = c->ExprCases(); + if ( exprs ) { - auto body = c->Body(); - auto uds = PropagateUDs(body, succ_UDs, succ_stmt, second_pass); - - auto exprs = c->ExprCases(); - if ( exprs ) - { - auto e_UDs = ExprUDs(exprs); - uds = UD_Union(uds, e_UDs); - } - - auto type_ids = c->TypeCases(); - if ( type_ids ) - for ( const auto& id : *type_ids ) - uds = RemoveID(id, uds); - - FoldInUDs(sw_UDs, uds); + auto e_UDs = ExprUDs(exprs); + uds = UD_Union(uds, e_UDs); } - auto e_UDs = ExprUDs(sw->StmtExpr()); + auto type_ids = c->TypeCases(); + if ( type_ids ) + for ( const auto& id : *type_ids ) + uds = RemoveID(id, uds); - if ( sw->HasDefault() ) - FoldInUDs(sw_UDs, e_UDs); - else - // keep successor definitions in the mix - FoldInUDs(sw_UDs, succ_UDs, e_UDs); - - return CreateUDs(s, sw_UDs); + FoldInUDs(sw_UDs, uds); } + auto e_UDs = ExprUDs(sw->StmtExpr()); + + if ( sw->HasDefault() ) + FoldInUDs(sw_UDs, e_UDs); + else + // keep successor definitions in the mix + FoldInUDs(sw_UDs, succ_UDs, e_UDs); + + return CreateUDs(s, sw_UDs); + } + case STMT_FOR: - { - auto f = s->AsForStmt(); - auto body = f->LoopBody(); + { + auto f = s->AsForStmt(); + auto body = f->LoopBody(); - // The loop body has two potential successors, itself - // and the successor of the entire "for" statement. - successor2[body] = succ_stmt; - auto body_UDs = PropagateUDs(body, succ_UDs, body, second_pass); + // The loop body has two potential successors, itself + // and the successor of the entire "for" statement. + successor2[body] = succ_stmt; + auto body_UDs = PropagateUDs(body, succ_UDs, body, second_pass); - auto e = f->LoopExpr(); - auto f_UDs = ExprUDs(e); - FoldInUDs(f_UDs, body_UDs); + auto e = f->LoopExpr(); + auto f_UDs = ExprUDs(e); + FoldInUDs(f_UDs, body_UDs); - // Confluence: loop the top UDs back around to the bottom. - auto bottom_UDs = UD_Union(f_UDs, succ_UDs); - (void)PropagateUDs(body, bottom_UDs, body, true); + // Confluence: loop the top UDs back around to the bottom. + auto bottom_UDs = UD_Union(f_UDs, succ_UDs); + (void)PropagateUDs(body, bottom_UDs, body, true); - auto ids = f->LoopVars(); - for ( const auto& id : *ids ) - RemoveUDFrom(f_UDs, id); + auto ids = f->LoopVars(); + for ( const auto& id : *ids ) + RemoveUDFrom(f_UDs, id); - auto val_var = f->ValueVar(); - if ( val_var ) - RemoveUDFrom(f_UDs, val_var.get()); + auto val_var = f->ValueVar(); + if ( val_var ) + RemoveUDFrom(f_UDs, val_var.get()); - // The loop might not execute at all. - FoldInUDs(f_UDs, succ_UDs); + // The loop might not execute at all. + FoldInUDs(f_UDs, succ_UDs); - return CreateUDs(s, f_UDs); - } + return CreateUDs(s, f_UDs); + } case STMT_WHILE: + { + auto w = s->AsWhileStmt(); + auto body = w->Body(); + auto cond_stmt = w->CondPredStmt(); + + // See note above for STMT_FOR regarding propagating + // around the loop. + auto succ = cond_stmt ? cond_stmt : body; + successor2[body.get()] = succ_stmt; + auto body_UDs = PropagateUDs(body.get(), succ_UDs, succ.get(), second_pass); + + const auto& cond = w->Condition(); + auto w_UDs = UD_Union(ExprUDs(cond.get()), body_UDs); + FoldInUDs(w_UDs, body_UDs); + + if ( cond_stmt ) { - auto w = s->AsWhileStmt(); - auto body = w->Body(); - auto cond_stmt = w->CondPredStmt(); + // Create a successor for the cond_stmt + // that has the correct UDs associated with it. + const auto& c_as_s = w->ConditionAsStmt(); + auto c_as_s_UDs = std::make_shared(w_UDs); + CreateUDs(c_as_s.get(), c_as_s_UDs); - // See note above for STMT_FOR regarding propagating - // around the loop. - auto succ = cond_stmt ? cond_stmt : body; - successor2[body.get()] = succ_stmt; - auto body_UDs = PropagateUDs(body.get(), succ_UDs, succ.get(), second_pass); - - const auto& cond = w->Condition(); - auto w_UDs = UD_Union(ExprUDs(cond.get()), body_UDs); - FoldInUDs(w_UDs, body_UDs); - - if ( cond_stmt ) - { - // Create a successor for the cond_stmt - // that has the correct UDs associated with it. - const auto& c_as_s = w->ConditionAsStmt(); - auto c_as_s_UDs = std::make_shared(w_UDs); - CreateUDs(c_as_s.get(), c_as_s_UDs); - - w_UDs = PropagateUDs(cond_stmt, w_UDs, c_as_s, second_pass); - } - - // Confluence: loop the top UDs back around to the bottom. - auto bottom_UDs = UD_Union(w_UDs, succ_UDs); - (void)PropagateUDs(body, bottom_UDs, succ, true); - - // The loop might not execute at all. - FoldInUDs(w_UDs, succ_UDs); - - return CreateUDs(s, w_UDs); + w_UDs = PropagateUDs(cond_stmt, w_UDs, c_as_s, second_pass); } + // Confluence: loop the top UDs back around to the bottom. + auto bottom_UDs = UD_Union(w_UDs, succ_UDs); + (void)PropagateUDs(body, bottom_UDs, succ, true); + + // The loop might not execute at all. + FoldInUDs(w_UDs, succ_UDs); + + return CreateUDs(s, w_UDs); + } + default: reporter->InternalError("non-reduced statement in use-def analysis"); } @@ -454,12 +454,12 @@ UDs UseDefs::ExprUDs(const Expr* e) break; case EXPR_FIELD_LHS_ASSIGN: - { - AddInExprUDs(uds, e->GetOp1().get()); - auto rhs_UDs = ExprUDs(e->GetOp2().get()); - uds = UD_Union(uds, rhs_UDs); - break; - } + { + AddInExprUDs(uds, e->GetOp1().get()); + auto rhs_UDs = ExprUDs(e->GetOp2().get()); + uds = UD_Union(uds, rhs_UDs); + break; + } case EXPR_INCR: case EXPR_DECR: @@ -467,41 +467,41 @@ UDs UseDefs::ExprUDs(const Expr* e) break; case EXPR_RECORD_CONSTRUCTOR: - { - auto r = static_cast(e); - AddInExprUDs(uds, r->Op().get()); - break; - } + { + auto r = static_cast(e); + AddInExprUDs(uds, r->Op().get()); + break; + } case EXPR_CONST: break; case EXPR_LAMBDA: - { - auto l = static_cast(e); - auto ids = l->OuterIDs(); + { + auto l = static_cast(e); + auto ids = l->OuterIDs(); - for ( const auto& id : ids ) - AddID(uds, id); - break; - } + for ( const auto& id : ids ) + AddID(uds, id); + break; + } case EXPR_CALL: - { - auto c = e->AsCallExpr(); - AddInExprUDs(uds, c->Func()); - AddInExprUDs(uds, c->Args()); - break; - } + { + auto c = e->AsCallExpr(); + AddInExprUDs(uds, c->Func()); + AddInExprUDs(uds, c->Args()); + break; + } case EXPR_LIST: - { - auto l = e->AsListExpr(); - for ( const auto& l_e : l->Exprs() ) - AddInExprUDs(uds, l_e); + { + auto l = e->AsListExpr(); + for ( const auto& l_e : l->Exprs() ) + AddInExprUDs(uds, l_e); - break; - } + break; + } default: auto op1 = e->GetOp1(); @@ -532,11 +532,11 @@ void UseDefs::AddInExprUDs(UDs uds, const Expr* e) break; case EXPR_LIST: - { - auto l = e->AsListExpr(); - for ( const auto& l_e : l->Exprs() ) - AddInExprUDs(uds, l_e); - } + { + auto l = e->AsListExpr(); + for ( const auto& l_e : l->Exprs() ) + AddInExprUDs(uds, l_e); + } break; case EXPR_EVENT: diff --git a/src/script_opt/ZAM/AM-Opt.cc b/src/script_opt/ZAM/AM-Opt.cc index b2ad28bc51..5af22bee01 100644 --- a/src/script_opt/ZAM/AM-Opt.cc +++ b/src/script_opt/ZAM/AM-Opt.cc @@ -362,43 +362,43 @@ void ZAMCompiler::ComputeFrameLifetimes() { case OP_NEXT_TABLE_ITER_VV: case OP_NEXT_TABLE_ITER_VAL_VAR_VVV: + { + // These assign to an arbitrary long list of variables. + auto& iter_vars = inst->aux->loop_vars; + auto depth = inst->loop_depth; + + for ( auto v : iter_vars ) { - // These assign to an arbitrary long list of variables. - auto& iter_vars = inst->aux->loop_vars; - auto depth = inst->loop_depth; + CheckSlotAssignment(v, inst); - for ( auto v : iter_vars ) - { - CheckSlotAssignment(v, inst); - - // Also mark it as usage throughout the - // loop. Otherwise, we risk pruning the - // variable if it happens to not be used - // (which will mess up the iteration logic) - // or doubling it up with some other value - // inside the loop (which will fail when - // the loop var has memory management - // associated with it). - ExtendLifetime(v, EndOfLoop(inst, depth)); - } - - // No need to check the additional "var" associated - // with OP_NEXT_TABLE_ITER_VAL_VAR_VVV as that's - // a slot-1 assignment. However, similar to other - // loop variables, mark this as a usage. - if ( inst->op == OP_NEXT_TABLE_ITER_VAL_VAR_VVV ) - ExtendLifetime(inst->v1, EndOfLoop(inst, depth)); + // Also mark it as usage throughout the + // loop. Otherwise, we risk pruning the + // variable if it happens to not be used + // (which will mess up the iteration logic) + // or doubling it up with some other value + // inside the loop (which will fail when + // the loop var has memory management + // associated with it). + ExtendLifetime(v, EndOfLoop(inst, depth)); } + + // No need to check the additional "var" associated + // with OP_NEXT_TABLE_ITER_VAL_VAR_VVV as that's + // a slot-1 assignment. However, similar to other + // loop variables, mark this as a usage. + if ( inst->op == OP_NEXT_TABLE_ITER_VAL_VAR_VVV ) + ExtendLifetime(inst->v1, EndOfLoop(inst, depth)); + } break; case OP_NEXT_TABLE_ITER_NO_VARS_VV: break; case OP_NEXT_TABLE_ITER_VAL_VAR_NO_VARS_VVV: - { - auto depth = inst->loop_depth; - ExtendLifetime(inst->v1, EndOfLoop(inst, depth)); - } + { + auto depth = inst->loop_depth; + ExtendLifetime(inst->v1, EndOfLoop(inst, depth)); + } break; case OP_NEXT_VECTOR_ITER_VVV: @@ -417,30 +417,30 @@ void ZAMCompiler::ComputeFrameLifetimes() case OP_INIT_TABLE_LOOP_VV: case OP_INIT_VECTOR_LOOP_VV: case OP_INIT_STRING_LOOP_VV: - { - // For all of these, the scope of the aggregate being - // looped over is the entire loop, even if it doesn't - // directly appear in it, and not just the initializer. - // For all three, the aggregate is in v1. - ASSERT(i < insts1.size() - 1); - auto succ = insts1[i + 1]; - ASSERT(succ->live); - auto depth = succ->loop_depth; - ExtendLifetime(inst->v1, EndOfLoop(succ, depth)); + { + // For all of these, the scope of the aggregate being + // looped over is the entire loop, even if it doesn't + // directly appear in it, and not just the initializer. + // For all three, the aggregate is in v1. + ASSERT(i < insts1.size() - 1); + auto succ = insts1[i + 1]; + ASSERT(succ->live); + auto depth = succ->loop_depth; + ExtendLifetime(inst->v1, EndOfLoop(succ, depth)); - // Important: we skip the usual UsesSlots analysis - // below since we've already set it, and don't want - // to perturb ExtendLifetime's consistency check. - continue; - } + // Important: we skip the usual UsesSlots analysis + // below since we've already set it, and don't want + // to perturb ExtendLifetime's consistency check. + continue; + } case OP_STORE_GLOBAL_V: - { - // Use of the global goes to here. - auto slot = frame_layout1[globalsI[inst->v1].id.get()]; - ExtendLifetime(slot, EndOfLoop(inst, 1)); - break; - } + { + // Use of the global goes to here. + auto slot = frame_layout1[globalsI[inst->v1].id.get()]; + ExtendLifetime(slot, EndOfLoop(inst, 1)); + break; + } default: // Look for slots in auxiliary information. @@ -559,15 +559,15 @@ void ZAMCompiler::ReMapFrame() { case OP_NEXT_TABLE_ITER_VV: case OP_NEXT_TABLE_ITER_VAL_VAR_VVV: + { + // Rewrite iteration variables. + auto& iter_vars = inst->aux->loop_vars; + for ( auto& v : iter_vars ) { - // Rewrite iteration variables. - auto& iter_vars = inst->aux->loop_vars; - for ( auto& v : iter_vars ) - { - ASSERT(v >= 0 && v < n1_slots); - v = frame1_to_frame2[v]; - } + ASSERT(v >= 0 && v < n1_slots); + v = frame1_to_frame2[v]; } + } break; default: diff --git a/src/script_opt/ZAM/Expr.cc b/src/script_opt/ZAM/Expr.cc index 35bdbd4a4f..41309849a0 100644 --- a/src/script_opt/ZAM/Expr.cc +++ b/src/script_opt/ZAM/Expr.cc @@ -24,32 +24,32 @@ const ZAMStmt ZAMCompiler::CompileExpr(const Expr* e) return CompileAssignExpr(static_cast(e)); case EXPR_INDEX_ASSIGN: - { - auto iae = static_cast(e); - auto t = iae->GetOp1()->GetType()->Tag(); - if ( t == TYPE_VECTOR ) - return AssignVecElems(iae); + { + auto iae = static_cast(e); + auto t = iae->GetOp1()->GetType()->Tag(); + if ( t == TYPE_VECTOR ) + return AssignVecElems(iae); - ASSERT(t == TYPE_TABLE); - return AssignTableElem(iae); - } + ASSERT(t == TYPE_TABLE); + return AssignTableElem(iae); + } case EXPR_FIELD_LHS_ASSIGN: - { - auto flhs = static_cast(e); - return CompileFieldLHSAssignExpr(flhs); - } + { + auto flhs = static_cast(e); + return CompileFieldLHSAssignExpr(flhs); + } case EXPR_SCHEDULE: return CompileScheduleExpr(static_cast(e)); case EXPR_EVENT: - { - auto ee = static_cast(e); - auto h = ee->Handler().Ptr(); - auto args = ee->Args(); - return EventHL(h, args); - } + { + auto ee = static_cast(e); + auto h = ee->Handler().Ptr(); + auto args = ee->Args(); + return EventHL(h, args); + } default: reporter->InternalError("bad statement type in ZAMCompile::CompileExpr"); @@ -1111,31 +1111,31 @@ const ZAMStmt ZAMCompiler::ArithCoerce(const NameExpr* n, const Expr* e) switch ( targ_it ) { case TYPE_INTERNAL_DOUBLE: - { - if ( op_it == TYPE_INTERNAL_INT ) - a = nt_is_vec ? OP_COERCE_DI_VEC_VV : OP_COERCE_DI_VV; - else - a = nt_is_vec ? OP_COERCE_DU_VEC_VV : OP_COERCE_DU_VV; - break; - } + { + if ( op_it == TYPE_INTERNAL_INT ) + a = nt_is_vec ? OP_COERCE_DI_VEC_VV : OP_COERCE_DI_VV; + else + a = nt_is_vec ? OP_COERCE_DU_VEC_VV : OP_COERCE_DU_VV; + break; + } case TYPE_INTERNAL_INT: - { - if ( op_it == TYPE_INTERNAL_UNSIGNED ) - a = nt_is_vec ? OP_COERCE_IU_VEC_VV : OP_COERCE_IU_VV; - else - a = nt_is_vec ? OP_COERCE_ID_VEC_VV : OP_COERCE_ID_VV; - break; - } + { + if ( op_it == TYPE_INTERNAL_UNSIGNED ) + a = nt_is_vec ? OP_COERCE_IU_VEC_VV : OP_COERCE_IU_VV; + else + a = nt_is_vec ? OP_COERCE_ID_VEC_VV : OP_COERCE_ID_VV; + break; + } case TYPE_INTERNAL_UNSIGNED: - { - if ( op_it == TYPE_INTERNAL_INT ) - a = nt_is_vec ? OP_COERCE_UI_VEC_VV : OP_COERCE_UI_VV; - else - a = nt_is_vec ? OP_COERCE_UD_VEC_VV : OP_COERCE_UD_VV; - break; - } + { + if ( op_it == TYPE_INTERNAL_INT ) + a = nt_is_vec ? OP_COERCE_UI_VEC_VV : OP_COERCE_UI_VV; + else + a = nt_is_vec ? OP_COERCE_UD_VEC_VV : OP_COERCE_UD_VV; + break; + } default: reporter->InternalError("bad target internal type in coercion"); diff --git a/src/script_opt/ZAM/Gen-ZAM.cc b/src/script_opt/ZAM/Gen-ZAM.cc index 40b8b9a820..f81e74b7bc 100644 --- a/src/script_opt/ZAM/Gen-ZAM.cc +++ b/src/script_opt/ZAM/Gen-ZAM.cc @@ -81,11 +81,11 @@ string find_type_accessor(ZAM_ExprType et) return "re_val"; default: - { - string acc = find_type_info(et).accessor; - transform(acc.begin(), acc.end(), acc.begin(), ::tolower); - return acc + "_val"; - } + { + string acc = find_type_info(et).accessor; + transform(acc.begin(), acc.end(), acc.begin(), ::tolower); + return acc + "_val"; + } } } diff --git a/src/script_opt/ZAM/Stmt.cc b/src/script_opt/ZAM/Stmt.cc index 14440537cf..01fbc3bcf7 100644 --- a/src/script_opt/ZAM/Stmt.cc +++ b/src/script_opt/ZAM/Stmt.cc @@ -36,11 +36,11 @@ const ZAMStmt ZAMCompiler::CompileStmt(const Stmt* s) return CompileDel(static_cast(s)); case STMT_EVENT: - { - auto es = static_cast(s); - auto e = static_cast(es->StmtExpr()); - return CompileExpr(e); - } + { + auto es = static_cast(s); + auto e = static_cast(es->StmtExpr()); + return CompileExpr(e); + } case STMT_WHILE: return CompileWhile(static_cast(s)); @@ -67,12 +67,12 @@ const ZAMStmt ZAMCompiler::CompileStmt(const Stmt* s) return CompileWhen(static_cast(s)); case STMT_CHECK_ANY_LEN: - { - auto cs = static_cast(s); - auto n = cs->StmtExpr()->AsNameExpr(); - auto expected_len = cs->ExpectedLen(); - return CheckAnyLenVi(n, expected_len); - } + { + auto cs = static_cast(s); + auto n = cs->StmtExpr()->AsNameExpr(); + auto expected_len = cs->ExpectedLen(); + return CheckAnyLenVi(n, expected_len); + } case STMT_NEXT: return CompileNext(); @@ -520,29 +520,29 @@ const ZAMStmt ZAMCompiler::ValueSwitch(const SwitchStmt* sw, const NameExpr* v, break; case TYPE_INTERNAL_STRING: - { - // This leaks, but only statically so not worth - // tracking the value for ultimate deletion. - auto sv = cv->AsString()->Render(); - std::string s(sv); - new_str_cases[s] = case_body_start; - delete[] sv; - break; - } + { + // This leaks, but only statically so not worth + // tracking the value for ultimate deletion. + auto sv = cv->AsString()->Render(); + std::string s(sv); + new_str_cases[s] = case_body_start; + delete[] sv; + break; + } case TYPE_INTERNAL_ADDR: - { - auto a = cv->AsAddr().AsString(); - new_str_cases[a] = case_body_start; - break; - } + { + auto a = cv->AsAddr().AsString(); + new_str_cases[a] = case_body_start; + break; + } case TYPE_INTERNAL_SUBNET: - { - auto n = cv->AsSubNet().AsString(); - new_str_cases[n] = case_body_start; - break; - } + { + auto n = cv->AsSubNet().AsString(); + new_str_cases[n] = case_body_start; + break; + } default: reporter->InternalError("bad recovered type when compiling switch"); diff --git a/src/threading/SerialTypes.cc b/src/threading/SerialTypes.cc index 6e8c89d915..a68640bc2f 100644 --- a/src/threading/SerialTypes.cc +++ b/src/threading/SerialTypes.cc @@ -144,23 +144,23 @@ bool Value::IsCompatibleType(Type* t, bool atomic_only) return ! atomic_only; case TYPE_TABLE: - { - if ( atomic_only ) - return false; + { + if ( atomic_only ) + return false; - if ( ! t->IsSet() ) - return false; + if ( ! t->IsSet() ) + return false; - return IsCompatibleType(t->AsSetType()->GetIndices()->GetPureType().get(), true); - } + return IsCompatibleType(t->AsSetType()->GetIndices()->GetPureType().get(), true); + } case TYPE_VECTOR: - { - if ( atomic_only ) - return false; + { + if ( atomic_only ) + return false; - return IsCompatibleType(t->AsVectorType()->Yield().get(), true); - } + return IsCompatibleType(t->AsVectorType()->Yield().get(), true); + } default: return false; @@ -193,81 +193,81 @@ bool Value::Read(detail::SerializationFormat* fmt) return fmt->Read(&val.uint_val, "uint"); case TYPE_PORT: + { + int proto; + if ( ! (fmt->Read(&val.port_val.port, "port") && fmt->Read(&proto, "proto")) ) { - int proto; - if ( ! (fmt->Read(&val.port_val.port, "port") && fmt->Read(&proto, "proto")) ) - { - return false; - } - - switch ( proto ) - { - case 0: - val.port_val.proto = TRANSPORT_UNKNOWN; - break; - case 1: - val.port_val.proto = TRANSPORT_TCP; - break; - case 2: - val.port_val.proto = TRANSPORT_UDP; - break; - case 3: - val.port_val.proto = TRANSPORT_ICMP; - break; - default: - return false; - } - - return true; + return false; } + switch ( proto ) + { + case 0: + val.port_val.proto = TRANSPORT_UNKNOWN; + break; + case 1: + val.port_val.proto = TRANSPORT_TCP; + break; + case 2: + val.port_val.proto = TRANSPORT_UDP; + break; + case 3: + val.port_val.proto = TRANSPORT_ICMP; + break; + default: + return false; + } + + return true; + } + case TYPE_ADDR: + { + char family; + + if ( ! fmt->Read(&family, "addr-family") ) + return false; + + switch ( family ) { - char family; + case 4: + val.addr_val.family = IPv4; + return fmt->Read(&val.addr_val.in.in4, "addr-in4"); - if ( ! fmt->Read(&family, "addr-family") ) - return false; - - switch ( family ) - { - case 4: - val.addr_val.family = IPv4; - return fmt->Read(&val.addr_val.in.in4, "addr-in4"); - - case 6: - val.addr_val.family = IPv6; - return fmt->Read(&val.addr_val.in.in6, "addr-in6"); - } - - // Can't be reached. - abort(); + case 6: + val.addr_val.family = IPv6; + return fmt->Read(&val.addr_val.in.in6, "addr-in6"); } + // Can't be reached. + abort(); + } + case TYPE_SUBNET: + { + char length; + char family; + + if ( ! (fmt->Read(&length, "subnet-len") && fmt->Read(&family, "subnet-family")) ) + return false; + + switch ( family ) { - char length; - char family; + case 4: + val.subnet_val.length = (uint8_t)length; + val.subnet_val.prefix.family = IPv4; + return fmt->Read(&val.subnet_val.prefix.in.in4, "subnet-in4"); - if ( ! (fmt->Read(&length, "subnet-len") && fmt->Read(&family, "subnet-family")) ) - return false; - - switch ( family ) - { - case 4: - val.subnet_val.length = (uint8_t)length; - val.subnet_val.prefix.family = IPv4; - return fmt->Read(&val.subnet_val.prefix.in.in4, "subnet-in4"); - - case 6: - val.subnet_val.length = (uint8_t)length; - val.subnet_val.prefix.family = IPv6; - return fmt->Read(&val.subnet_val.prefix.in.in6, "subnet-in6"); - } - - // Can't be reached. - abort(); + case 6: + val.subnet_val.length = (uint8_t)length; + val.subnet_val.prefix.family = IPv6; + return fmt->Read(&val.subnet_val.prefix.in.in6, "subnet-in6"); } + // Can't be reached. + abort(); + } + case TYPE_DOUBLE: case TYPE_TIME: case TYPE_INTERVAL: @@ -280,41 +280,41 @@ bool Value::Read(detail::SerializationFormat* fmt) return fmt->Read(&val.string_val.data, &val.string_val.length, "string"); case TYPE_TABLE: + { + if ( ! fmt->Read(&val.set_val.size, "set_size") ) + return false; + + val.set_val.vals = new Value*[val.set_val.size]; + + for ( bro_int_t i = 0; i < val.set_val.size; ++i ) { - if ( ! fmt->Read(&val.set_val.size, "set_size") ) + val.set_val.vals[i] = new Value; + + if ( ! val.set_val.vals[i]->Read(fmt) ) return false; - - val.set_val.vals = new Value*[val.set_val.size]; - - for ( bro_int_t i = 0; i < val.set_val.size; ++i ) - { - val.set_val.vals[i] = new Value; - - if ( ! val.set_val.vals[i]->Read(fmt) ) - return false; - } - - return true; } + return true; + } + case TYPE_VECTOR: + { + if ( ! fmt->Read(&val.vector_val.size, "vector_size") ) + return false; + + val.vector_val.vals = new Value*[val.vector_val.size]; + + for ( bro_int_t i = 0; i < val.vector_val.size; ++i ) { - if ( ! fmt->Read(&val.vector_val.size, "vector_size") ) + val.vector_val.vals[i] = new Value; + + if ( ! val.vector_val.vals[i]->Read(fmt) ) return false; - - val.vector_val.vals = new Value*[val.vector_val.size]; - - for ( bro_int_t i = 0; i < val.vector_val.size; ++i ) - { - val.vector_val.vals[i] = new Value; - - if ( ! val.vector_val.vals[i]->Read(fmt) ) - return false; - } - - return true; } + return true; + } + default: reporter->InternalError("unsupported type %s in Value::Read", type_name(type)); } @@ -344,42 +344,42 @@ bool Value::Write(detail::SerializationFormat* fmt) const return fmt->Write(val.port_val.port, "port") && fmt->Write(val.port_val.proto, "proto"); case TYPE_ADDR: + { + switch ( val.addr_val.family ) { - switch ( val.addr_val.family ) - { - case IPv4: - return fmt->Write((char)4, "addr-family") && - fmt->Write(val.addr_val.in.in4, "addr-in4"); + case IPv4: + return fmt->Write((char)4, "addr-family") && + fmt->Write(val.addr_val.in.in4, "addr-in4"); - case IPv6: - return fmt->Write((char)6, "addr-family") && - fmt->Write(val.addr_val.in.in6, "addr-in6"); - } - - // Can't be reached. - abort(); + case IPv6: + return fmt->Write((char)6, "addr-family") && + fmt->Write(val.addr_val.in.in6, "addr-in6"); } + // Can't be reached. + abort(); + } + case TYPE_SUBNET: + { + if ( ! fmt->Write((char)val.subnet_val.length, "subnet-length") ) + return false; + + switch ( val.subnet_val.prefix.family ) { - if ( ! fmt->Write((char)val.subnet_val.length, "subnet-length") ) - return false; + case IPv4: + return fmt->Write((char)4, "subnet-family") && + fmt->Write(val.subnet_val.prefix.in.in4, "subnet-in4"); - switch ( val.subnet_val.prefix.family ) - { - case IPv4: - return fmt->Write((char)4, "subnet-family") && - fmt->Write(val.subnet_val.prefix.in.in4, "subnet-in4"); - - case IPv6: - return fmt->Write((char)6, "subnet-family") && - fmt->Write(val.subnet_val.prefix.in.in6, "subnet-in6"); - } - - // Can't be reached. - abort(); + case IPv6: + return fmt->Write((char)6, "subnet-family") && + fmt->Write(val.subnet_val.prefix.in.in6, "subnet-in6"); } + // Can't be reached. + abort(); + } + case TYPE_DOUBLE: case TYPE_TIME: case TYPE_INTERVAL: @@ -392,33 +392,33 @@ bool Value::Write(detail::SerializationFormat* fmt) const return fmt->Write(val.string_val.data, val.string_val.length, "string"); case TYPE_TABLE: + { + if ( ! fmt->Write(val.set_val.size, "set_size") ) + return false; + + for ( int i = 0; i < val.set_val.size; ++i ) { - if ( ! fmt->Write(val.set_val.size, "set_size") ) + if ( ! val.set_val.vals[i]->Write(fmt) ) return false; - - for ( int i = 0; i < val.set_val.size; ++i ) - { - if ( ! val.set_val.vals[i]->Write(fmt) ) - return false; - } - - return true; } + return true; + } + case TYPE_VECTOR: + { + if ( ! fmt->Write(val.vector_val.size, "vector_size") ) + return false; + + for ( int i = 0; i < val.vector_val.size; ++i ) { - if ( ! fmt->Write(val.vector_val.size, "vector_size") ) + if ( ! val.vector_val.vals[i]->Write(fmt) ) return false; - - for ( int i = 0; i < val.vector_val.size; ++i ) - { - if ( ! val.vector_val.vals[i]->Write(fmt) ) - return false; - } - - return true; } + return true; + } + default: reporter->InternalError("unsupported type %s in Value::Write", type_name(type)); } @@ -464,204 +464,204 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e return new IntervalVal(val->val.double_val); case TYPE_STRING: - { - auto* s = new String((const u_char*)val->val.string_val.data, - val->val.string_val.length, true); - return new StringVal(s); - } + { + auto* s = new String((const u_char*)val->val.string_val.data, + val->val.string_val.length, true); + return new StringVal(s); + } case TYPE_PORT: return val_mgr->Port(val->val.port_val.port, val->val.port_val.proto)->Ref(); case TYPE_ADDR: + { + IPAddr* addr = nullptr; + switch ( val->val.addr_val.family ) { - IPAddr* addr = nullptr; - switch ( val->val.addr_val.family ) - { - case IPv4: - addr = new IPAddr(val->val.addr_val.in.in4); - break; + case IPv4: + addr = new IPAddr(val->val.addr_val.in.in4); + break; - case IPv6: - addr = new IPAddr(val->val.addr_val.in.in6); - break; + case IPv6: + addr = new IPAddr(val->val.addr_val.in.in6); + break; - default: - assert(false); - } - - auto* addrval = new AddrVal(*addr); - delete addr; - return addrval; + default: + assert(false); } + auto* addrval = new AddrVal(*addr); + delete addr; + return addrval; + } + case TYPE_SUBNET: + { + IPAddr* addr = nullptr; + switch ( val->val.subnet_val.prefix.family ) { - IPAddr* addr = nullptr; - switch ( val->val.subnet_val.prefix.family ) - { - case IPv4: - addr = new IPAddr(val->val.subnet_val.prefix.in.in4); - break; + case IPv4: + addr = new IPAddr(val->val.subnet_val.prefix.in.in4); + break; - case IPv6: - addr = new IPAddr(val->val.subnet_val.prefix.in.in6); - break; + case IPv6: + addr = new IPAddr(val->val.subnet_val.prefix.in.in6); + break; - default: - assert(false); - } - - auto* subnetval = new SubNetVal(*addr, val->val.subnet_val.length); - delete addr; - return subnetval; + default: + assert(false); } + auto* subnetval = new SubNetVal(*addr, val->val.subnet_val.length); + delete addr; + return subnetval; + } + case TYPE_PATTERN: - { - auto* re = new RE_Matcher(val->val.pattern_text_val); - re->Compile(); - return new PatternVal(re); - } + { + auto* re = new RE_Matcher(val->val.pattern_text_val); + re->Compile(); + return new PatternVal(re); + } case TYPE_TABLE: + { + TypeListPtr set_index; + if ( val->val.set_val.size == 0 && + (val->subtype == TYPE_VOID || val->subtype == TYPE_ENUM) ) + // don't know type - unspecified table. + set_index = make_intrusive(); + else { - TypeListPtr set_index; - if ( val->val.set_val.size == 0 && - (val->subtype == TYPE_VOID || val->subtype == TYPE_ENUM) ) - // don't know type - unspecified table. - set_index = make_intrusive(); - else + // all entries have to have the same type... + TypeTag stag = val->subtype; + if ( stag == TYPE_VOID ) + stag = val->val.set_val.vals[0]->type; + + TypePtr index_type; + + if ( stag == TYPE_ENUM ) { - // all entries have to have the same type... - TypeTag stag = val->subtype; - if ( stag == TYPE_VOID ) - stag = val->val.set_val.vals[0]->type; + // Enums are not a base-type, so need to look it up. + const auto& sv = val->val.set_val.vals[0]->val.string_val; + std::string enum_name(sv.data, sv.length); + const auto& enum_id = detail::global_scope()->Find(enum_name); - TypePtr index_type; - - if ( stag == TYPE_ENUM ) + if ( ! enum_id ) { - // Enums are not a base-type, so need to look it up. - const auto& sv = val->val.set_val.vals[0]->val.string_val; - std::string enum_name(sv.data, sv.length); - const auto& enum_id = detail::global_scope()->Find(enum_name); + reporter->Warning("Value '%s' of source '%s' is not a valid enum.", + enum_name.data(), source.c_str()); - if ( ! enum_id ) - { - reporter->Warning("Value '%s' of source '%s' is not a valid enum.", - enum_name.data(), source.c_str()); - - have_error = true; - return nullptr; - } - - index_type = enum_id->GetType(); - } - else - index_type = base_type(stag); - - set_index = make_intrusive(index_type); - set_index->Append(std::move(index_type)); - } - - auto s = make_intrusive(std::move(set_index), nullptr); - auto t = make_intrusive(std::move(s)); - for ( int j = 0; j < val->val.set_val.size; j++ ) - { - Val* assignval = ValueToVal(source, val->val.set_val.vals[j], have_error); - if ( have_error ) + have_error = true; return nullptr; + } - t->Assign({AdoptRef{}, assignval}, nullptr); + index_type = enum_id->GetType(); } + else + index_type = base_type(stag); - return t.release(); + set_index = make_intrusive(index_type); + set_index->Append(std::move(index_type)); } + auto s = make_intrusive(std::move(set_index), nullptr); + auto t = make_intrusive(std::move(s)); + for ( int j = 0; j < val->val.set_val.size; j++ ) + { + Val* assignval = ValueToVal(source, val->val.set_val.vals[j], have_error); + if ( have_error ) + return nullptr; + + t->Assign({AdoptRef{}, assignval}, nullptr); + } + + return t.release(); + } + case TYPE_VECTOR: + { + TypePtr type; + + if ( val->val.vector_val.size == 0 && + (val->subtype == TYPE_VOID || val->subtype == TYPE_ENUM) ) + // don't know type - unspecified table. + type = base_type(TYPE_ANY); + else { - TypePtr type; - - if ( val->val.vector_val.size == 0 && - (val->subtype == TYPE_VOID || val->subtype == TYPE_ENUM) ) - // don't know type - unspecified table. - type = base_type(TYPE_ANY); - else + // all entries have to have the same type... + if ( val->subtype == TYPE_VOID ) + type = base_type(val->val.vector_val.vals[0]->type); + else if ( val->subtype == TYPE_ENUM ) { - // all entries have to have the same type... - if ( val->subtype == TYPE_VOID ) - type = base_type(val->val.vector_val.vals[0]->type); - else if ( val->subtype == TYPE_ENUM ) + // Enums are not a base-type, so need to look it up. + const auto& sv = val->val.vector_val.vals[0]->val.string_val; + std::string enum_name(sv.data, sv.length); + const auto& enum_id = detail::global_scope()->Find(enum_name); + + if ( ! enum_id ) { - // Enums are not a base-type, so need to look it up. - const auto& sv = val->val.vector_val.vals[0]->val.string_val; - std::string enum_name(sv.data, sv.length); - const auto& enum_id = detail::global_scope()->Find(enum_name); + reporter->Warning("Value '%s' of source '%s' is not a valid enum.", + enum_name.data(), source.c_str()); - if ( ! enum_id ) - { - reporter->Warning("Value '%s' of source '%s' is not a valid enum.", - enum_name.data(), source.c_str()); - - have_error = true; - return nullptr; - } - - type = enum_id->GetType(); - } - else - type = base_type(val->subtype); - } - - auto vt = make_intrusive(std::move(type)); - auto v = make_intrusive(std::move(vt)); - - for ( int j = 0; j < val->val.vector_val.size; j++ ) - { - auto el = ValueToVal(source, val->val.vector_val.vals[j], have_error); - if ( have_error ) + have_error = true; return nullptr; + } - v->Assign(j, {AdoptRef{}, el}); + type = enum_id->GetType(); } - - return v.release(); + else + type = base_type(val->subtype); } + auto vt = make_intrusive(std::move(type)); + auto v = make_intrusive(std::move(vt)); + + for ( int j = 0; j < val->val.vector_val.size; j++ ) + { + auto el = ValueToVal(source, val->val.vector_val.vals[j], have_error); + if ( have_error ) + return nullptr; + + v->Assign(j, {AdoptRef{}, el}); + } + + return v.release(); + } + case TYPE_ENUM: + { + // Convert to string first to not have to deal with missing + // \0's... + std::string enum_string(val->val.string_val.data, val->val.string_val.length); + + // let's try looking it up by global ID. + const auto& id = detail::lookup_ID(enum_string.c_str(), detail::GLOBAL_MODULE_NAME); + + if ( ! id || ! id->IsEnumConst() ) { - // Convert to string first to not have to deal with missing - // \0's... - std::string enum_string(val->val.string_val.data, val->val.string_val.length); + reporter->Warning("Value '%s' for source '%s' is not a valid enum.", + enum_string.c_str(), source.c_str()); - // let's try looking it up by global ID. - const auto& id = detail::lookup_ID(enum_string.c_str(), detail::GLOBAL_MODULE_NAME); - - if ( ! id || ! id->IsEnumConst() ) - { - reporter->Warning("Value '%s' for source '%s' is not a valid enum.", - enum_string.c_str(), source.c_str()); - - have_error = true; - return nullptr; - } - - EnumType* t = id->GetType()->AsEnumType(); - int intval = t->Lookup(id->ModuleName(), id->Name()); - if ( intval < 0 ) - { - reporter->Warning("Enum value '%s' for source '%s' not found.", - enum_string.c_str(), source.c_str()); - - have_error = true; - return nullptr; - } - - auto rval = t->GetEnumVal(intval); - return rval.release(); + have_error = true; + return nullptr; } + EnumType* t = id->GetType()->AsEnumType(); + int intval = t->Lookup(id->ModuleName(), id->Name()); + if ( intval < 0 ) + { + reporter->Warning("Enum value '%s' for source '%s' not found.", enum_string.c_str(), + source.c_str()); + + have_error = true; + return nullptr; + } + + auto rval = t->GetEnumVal(intval); + return rval.release(); + } + default: reporter->InternalError("Unsupported type in SerialTypes::ValueToVal from source %s", source.c_str()); diff --git a/src/threading/formatters/Ascii.cc b/src/threading/formatters/Ascii.cc index 9663ec560e..d475f11399 100644 --- a/src/threading/formatters/Ascii.cc +++ b/src/threading/formatters/Ascii.cc @@ -123,80 +123,80 @@ bool Ascii::Describe(ODesc* desc, Value* val, const string& name) const case TYPE_STRING: case TYPE_FILE: case TYPE_FUNC: + { + int size = val->val.string_val.length; + const char* data = val->val.string_val.data; + + if ( ! size ) { - int size = val->val.string_val.length; - const char* data = val->val.string_val.data; - - if ( ! size ) - { - desc->Add(separators.empty_field); - break; - } - - if ( escapeReservedContent(desc, separators.unset_field, data, size) ) - break; - - if ( escapeReservedContent(desc, separators.empty_field, data, size) ) - break; - - desc->AddN(data, size); + desc->Add(separators.empty_field); break; } + if ( escapeReservedContent(desc, separators.unset_field, data, size) ) + break; + + if ( escapeReservedContent(desc, separators.empty_field, data, size) ) + break; + + desc->AddN(data, size); + break; + } + case TYPE_TABLE: + { + if ( ! val->val.set_val.size ) { - if ( ! val->val.set_val.size ) - { - desc->Add(separators.empty_field); - break; - } - - desc->AddEscapeSequence(separators.set_separator); - - for ( bro_int_t j = 0; j < val->val.set_val.size; j++ ) - { - if ( j > 0 ) - desc->AddRaw(separators.set_separator); - - if ( ! Describe(desc, val->val.set_val.vals[j]) ) - { - desc->RemoveEscapeSequence(separators.set_separator); - return false; - } - } - - desc->RemoveEscapeSequence(separators.set_separator); - + desc->Add(separators.empty_field); break; } + desc->AddEscapeSequence(separators.set_separator); + + for ( bro_int_t j = 0; j < val->val.set_val.size; j++ ) + { + if ( j > 0 ) + desc->AddRaw(separators.set_separator); + + if ( ! Describe(desc, val->val.set_val.vals[j]) ) + { + desc->RemoveEscapeSequence(separators.set_separator); + return false; + } + } + + desc->RemoveEscapeSequence(separators.set_separator); + + break; + } + case TYPE_VECTOR: + { + if ( ! val->val.vector_val.size ) { - if ( ! val->val.vector_val.size ) - { - desc->Add(separators.empty_field); - break; - } - - desc->AddEscapeSequence(separators.set_separator); - - for ( bro_int_t j = 0; j < val->val.vector_val.size; j++ ) - { - if ( j > 0 ) - desc->AddRaw(separators.set_separator); - - if ( ! Describe(desc, val->val.vector_val.vals[j]) ) - { - desc->RemoveEscapeSequence(separators.set_separator); - return false; - } - } - - desc->RemoveEscapeSequence(separators.set_separator); - + desc->Add(separators.empty_field); break; } + desc->AddEscapeSequence(separators.set_separator); + + for ( bro_int_t j = 0; j < val->val.vector_val.size; j++ ) + { + if ( j > 0 ) + desc->AddRaw(separators.set_separator); + + if ( ! Describe(desc, val->val.vector_val.vals[j]) ) + { + desc->RemoveEscapeSequence(separators.set_separator); + return false; + } + } + + desc->RemoveEscapeSequence(separators.set_separator); + + break; + } + default: GetThread()->Warning( GetThread()->Fmt("Ascii writer unsupported field format %d", val->type)); @@ -222,30 +222,30 @@ Value* Ascii::ParseValue(const string& s, const string& name, TypeTag type, Type { case TYPE_ENUM: case TYPE_STRING: - { - string unescaped = util::get_unescaped_string(s); - val->val.string_val.length = unescaped.size(); - val->val.string_val.data = new char[val->val.string_val.length]; - // we do not need a zero-byte at the end - the input manager adds that explicitly - memcpy(val->val.string_val.data, unescaped.data(), unescaped.size()); - break; - } + { + string unescaped = util::get_unescaped_string(s); + val->val.string_val.length = unescaped.size(); + val->val.string_val.data = new char[val->val.string_val.length]; + // we do not need a zero-byte at the end - the input manager adds that explicitly + memcpy(val->val.string_val.data, unescaped.data(), unescaped.size()); + break; + } case TYPE_BOOL: + { + auto stripped = util::strstrip(s); + if ( stripped == "T" || stripped == "1" ) + val->val.int_val = 1; + else if ( stripped == "F" || stripped == "0" ) + val->val.int_val = 0; + else { - auto stripped = util::strstrip(s); - if ( stripped == "T" || stripped == "1" ) - val->val.int_val = 1; - else if ( stripped == "F" || stripped == "0" ) - val->val.int_val = 0; - else - { - GetThread()->Warning(GetThread()->Fmt("Field: %s Invalid value for boolean: %s", - name.c_str(), start)); - goto parse_error; - } - break; + GetThread()->Warning(GetThread()->Fmt("Field: %s Invalid value for boolean: %s", + name.c_str(), start)); + goto parse_error; } + break; + } case TYPE_INT: val->val.int_val = strtoll(start, &end, 10); @@ -268,91 +268,91 @@ Value* Ascii::ParseValue(const string& s, const string& name, TypeTag type, Type break; case TYPE_PORT: + { + auto stripped = util::strstrip(s); + val->val.port_val.proto = TRANSPORT_UNKNOWN; + pos = stripped.find('/'); + string numberpart; + if ( pos != std::string::npos && stripped.length() > pos + 1 ) { - auto stripped = util::strstrip(s); - val->val.port_val.proto = TRANSPORT_UNKNOWN; - pos = stripped.find('/'); - string numberpart; - if ( pos != std::string::npos && stripped.length() > pos + 1 ) - { - auto proto = stripped.substr(pos + 1); - if ( util::strtolower(proto) == "tcp" ) - val->val.port_val.proto = TRANSPORT_TCP; - else if ( util::strtolower(proto) == "udp" ) - val->val.port_val.proto = TRANSPORT_UDP; - else if ( util::strtolower(proto) == "icmp" ) - val->val.port_val.proto = TRANSPORT_ICMP; - else if ( util::strtolower(proto) == "unknown" ) - val->val.port_val.proto = TRANSPORT_UNKNOWN; - else - GetThread()->Warning(GetThread()->Fmt( - "Port '%s' contained unknown protocol '%s'", s.c_str(), proto.c_str())); - } - - if ( pos != std::string::npos && pos > 0 ) - { - numberpart = stripped.substr(0, pos); - start = numberpart.c_str(); - } - val->val.port_val.port = strtoull(start, &end, 10); - if ( CheckNumberError(start, end, true) ) - goto parse_error; + auto proto = stripped.substr(pos + 1); + if ( util::strtolower(proto) == "tcp" ) + val->val.port_val.proto = TRANSPORT_TCP; + else if ( util::strtolower(proto) == "udp" ) + val->val.port_val.proto = TRANSPORT_UDP; + else if ( util::strtolower(proto) == "icmp" ) + val->val.port_val.proto = TRANSPORT_ICMP; + else if ( util::strtolower(proto) == "unknown" ) + val->val.port_val.proto = TRANSPORT_UNKNOWN; + else + GetThread()->Warning(GetThread()->Fmt( + "Port '%s' contained unknown protocol '%s'", s.c_str(), proto.c_str())); } + + if ( pos != std::string::npos && pos > 0 ) + { + numberpart = stripped.substr(0, pos); + start = numberpart.c_str(); + } + val->val.port_val.port = strtoull(start, &end, 10); + if ( CheckNumberError(start, end, true) ) + goto parse_error; + } break; case TYPE_SUBNET: + { + string unescaped = util::strstrip(util::get_unescaped_string(s)); + size_t pos = unescaped.find('/'); + if ( pos == unescaped.npos ) { - string unescaped = util::strstrip(util::get_unescaped_string(s)); - size_t pos = unescaped.find('/'); - if ( pos == unescaped.npos ) - { - GetThread()->Warning(GetThread()->Fmt("Invalid value for subnet: %s", start)); - goto parse_error; - } - - string width_str = unescaped.substr(pos + 1); - uint8_t width = (uint8_t)strtol(width_str.c_str(), &end, 10); - - if ( CheckNumberError(start, end) ) - goto parse_error; - - string addr = unescaped.substr(0, pos); - - val->val.subnet_val.prefix = ParseAddr(addr); - val->val.subnet_val.length = width; - break; - } - - case TYPE_ADDR: - { - string unescaped = util::strstrip(util::get_unescaped_string(s)); - val->val.addr_val = ParseAddr(unescaped); - break; - } - - case TYPE_PATTERN: - { - string candidate = util::get_unescaped_string(s); - // A string is a candidate pattern iff it begins and ends with - // a '/'. Rather or not the rest of the string is legal will - // be determined later when it is given to the RE engine. - if ( candidate.size() >= 2 ) - { - if ( candidate.front() == candidate.back() && candidate.back() == '/' ) - { - // Remove the '/'s - candidate.erase(0, 1); - candidate.erase(candidate.size() - 1); - val->val.pattern_text_val = util::copy_string(candidate.c_str()); - break; - } - } - - GetThread()->Warning(GetThread()->Fmt("String '%s' contained no parseable pattern.", - candidate.c_str())); + GetThread()->Warning(GetThread()->Fmt("Invalid value for subnet: %s", start)); goto parse_error; } + string width_str = unescaped.substr(pos + 1); + uint8_t width = (uint8_t)strtol(width_str.c_str(), &end, 10); + + if ( CheckNumberError(start, end) ) + goto parse_error; + + string addr = unescaped.substr(0, pos); + + val->val.subnet_val.prefix = ParseAddr(addr); + val->val.subnet_val.length = width; + break; + } + + case TYPE_ADDR: + { + string unescaped = util::strstrip(util::get_unescaped_string(s)); + val->val.addr_val = ParseAddr(unescaped); + break; + } + + case TYPE_PATTERN: + { + string candidate = util::get_unescaped_string(s); + // A string is a candidate pattern iff it begins and ends with + // a '/'. Rather or not the rest of the string is legal will + // be determined later when it is given to the RE engine. + if ( candidate.size() >= 2 ) + { + if ( candidate.front() == candidate.back() && candidate.back() == '/' ) + { + // Remove the '/'s + candidate.erase(0, 1); + candidate.erase(candidate.size() - 1); + val->val.pattern_text_val = util::copy_string(candidate.c_str()); + break; + } + } + + GetThread()->Warning( + GetThread()->Fmt("String '%s' contained no parseable pattern.", candidate.c_str())); + goto parse_error; + } + case TYPE_TABLE: case TYPE_VECTOR: // First - common initialization diff --git a/src/threading/formatters/JSON.cc b/src/threading/formatters/JSON.cc index 838788ca46..5e3449cbdc 100644 --- a/src/threading/formatters/JSON.cc +++ b/src/threading/formatters/JSON.cc @@ -127,80 +127,79 @@ void JSON::BuildJSON(NullDoubleWriter& writer, Value* val, const std::string& na break; case TYPE_TIME: + { + if ( timestamps == TS_ISO8601 ) { - if ( timestamps == TS_ISO8601 ) + char buffer[40]; + char buffer2[48]; + time_t the_time = time_t(floor(val->val.double_val)); + struct tm t; + + if ( ! gmtime_r(&the_time, &t) || + ! strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%S", &t) ) { - char buffer[40]; - char buffer2[48]; - time_t the_time = time_t(floor(val->val.double_val)); - struct tm t; - - if ( ! gmtime_r(&the_time, &t) || - ! strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%S", &t) ) - { - GetThread()->Error(GetThread()->Fmt( - "json formatter: failure getting time: (%lf)", val->val.double_val)); - // This was a failure, doesn't really matter what gets put here - // but it should probably stand out... - writer.String("2000-01-01T00:00:00.000000"); - } - else - { - double integ; - double frac = modf(val->val.double_val, &integ); - - if ( frac < 0 ) - frac += 1; - - snprintf(buffer2, sizeof(buffer2), "%s.%06.0fZ", buffer, - fabs(frac) * 1000000); - writer.String(buffer2, strlen(buffer2)); - } + GetThread()->Error(GetThread()->Fmt( + "json formatter: failure getting time: (%lf)", val->val.double_val)); + // This was a failure, doesn't really matter what gets put here + // but it should probably stand out... + writer.String("2000-01-01T00:00:00.000000"); } - - else if ( timestamps == TS_EPOCH ) - writer.Double(val->val.double_val); - - else if ( timestamps == TS_MILLIS ) + else { - // ElasticSearch uses milliseconds for timestamps - writer.Uint64((uint64_t)(val->val.double_val * 1000)); - } + double integ; + double frac = modf(val->val.double_val, &integ); - break; + if ( frac < 0 ) + frac += 1; + + snprintf(buffer2, sizeof(buffer2), "%s.%06.0fZ", buffer, fabs(frac) * 1000000); + writer.String(buffer2, strlen(buffer2)); + } } + else if ( timestamps == TS_EPOCH ) + writer.Double(val->val.double_val); + + else if ( timestamps == TS_MILLIS ) + { + // ElasticSearch uses milliseconds for timestamps + writer.Uint64((uint64_t)(val->val.double_val * 1000)); + } + + break; + } + case TYPE_ENUM: case TYPE_STRING: case TYPE_FILE: case TYPE_FUNC: - { - writer.String(util::json_escape_utf8( - std::string(val->val.string_val.data, val->val.string_val.length))); - break; - } + { + writer.String(util::json_escape_utf8( + std::string(val->val.string_val.data, val->val.string_val.length))); + break; + } case TYPE_TABLE: - { - writer.StartArray(); + { + writer.StartArray(); - for ( bro_int_t idx = 0; idx < val->val.set_val.size; idx++ ) - BuildJSON(writer, val->val.set_val.vals[idx]); + for ( bro_int_t idx = 0; idx < val->val.set_val.size; idx++ ) + BuildJSON(writer, val->val.set_val.vals[idx]); - writer.EndArray(); - break; - } + writer.EndArray(); + break; + } case TYPE_VECTOR: - { - writer.StartArray(); + { + writer.StartArray(); - for ( bro_int_t idx = 0; idx < val->val.vector_val.size; idx++ ) - BuildJSON(writer, val->val.vector_val.vals[idx]); + for ( bro_int_t idx = 0; idx < val->val.vector_val.size; idx++ ) + BuildJSON(writer, val->val.vector_val.vals[idx]); - writer.EndArray(); - break; - } + writer.EndArray(); + break; + } default: reporter->Warning("Unhandled type in JSON::BuildJSON"); diff --git a/src/util.cc b/src/util.cc index 484bb5236c..14241481e6 100644 --- a/src/util.cc +++ b/src/util.cc @@ -183,67 +183,67 @@ int expand_escape(const char*& s) case '5': case '6': case '7': - { // \{1,3} - --s; // put back the first octal digit - const char* start = s; + { // \{1,3} + --s; // put back the first octal digit + const char* start = s; - // require at least one octal digit and parse at most three + // require at least one octal digit and parse at most three - int result = parse_octal_digit(*s++); + int result = parse_octal_digit(*s++); - if ( result < 0 ) - { - reporter->Error("bad octal escape: %s", start); - return 0; - } + if ( result < 0 ) + { + reporter->Error("bad octal escape: %s", start); + return 0; + } - // second digit? - int digit = parse_octal_digit(*s); + // second digit? + int digit = parse_octal_digit(*s); + + if ( digit >= 0 ) + { + result = (result << 3) | digit; + ++s; + + // third digit? + digit = parse_octal_digit(*s); if ( digit >= 0 ) { result = (result << 3) | digit; ++s; - - // third digit? - digit = parse_octal_digit(*s); - - if ( digit >= 0 ) - { - result = (result << 3) | digit; - ++s; - } } - - return result; } + return result; + } + case 'x': - { /* \x */ - const char* start = s; + { /* \x */ + const char* start = s; - // Look at most 2 characters, so that "\x0ddir" -> "^Mdir". + // Look at most 2 characters, so that "\x0ddir" -> "^Mdir". - int result = parse_hex_digit(*s++); + int result = parse_hex_digit(*s++); - if ( result < 0 ) - { - reporter->Error("bad hexadecimal escape: %s", start); - return 0; - } - - // second digit? - int digit = parse_hex_digit(*s); - - if ( digit >= 0 ) - { - result = (result << 4) | digit; - ++s; - } - - return result; + if ( result < 0 ) + { + reporter->Error("bad hexadecimal escape: %s", start); + return 0; } + // second digit? + int digit = parse_hex_digit(*s); + + if ( digit >= 0 ) + { + result = (result << 4) | digit; + ++s; + } + + return result; + } + default: return s[-1]; } diff --git a/src/zeekygen/Target.cc b/src/zeekygen/Target.cc index 04c8a1921d..b03d7b8e2b 100644 --- a/src/zeekygen/Target.cc +++ b/src/zeekygen/Target.cc @@ -81,38 +81,37 @@ static void write_plugin_components(FILE* f, const plugin::Plugin* p) switch ( component->Type() ) { case plugin::component::ANALYZER: - { - const analyzer::Component* c = - dynamic_cast(component); + { + const analyzer::Component* c = dynamic_cast(component); - if ( c ) - write_analyzer_component(f, c); - else - reporter->InternalError("component type mismatch"); - } + if ( c ) + write_analyzer_component(f, c); + else + reporter->InternalError("component type mismatch"); + } break; case plugin::component::PACKET_ANALYZER: - { - const packet_analysis::Component* c = - dynamic_cast(component); + { + const packet_analysis::Component* c = + dynamic_cast(component); - if ( c ) - write_analyzer_component(f, c); - else - reporter->InternalError("component type mismatch"); - } + if ( c ) + write_analyzer_component(f, c); + else + reporter->InternalError("component type mismatch"); + } break; case plugin::component::FILE_ANALYZER: - { - const auto* c = dynamic_cast(component); + { + const auto* c = dynamic_cast(component); - if ( c ) - write_analyzer_component(f, c); - else - reporter->InternalError("component type mismatch"); - } + if ( c ) + write_analyzer_component(f, c); + else + reporter->InternalError("component type mismatch"); + } break; case plugin::component::READER: diff --git a/src/zeekygen/utils.cc b/src/zeekygen/utils.cc index 1922727e83..b79e91fe88 100644 --- a/src/zeekygen/utils.cc +++ b/src/zeekygen/utils.cc @@ -170,19 +170,19 @@ std::optional source_code_range(const zeek::detail::ID* id) switch ( type->Tag() ) { case TYPE_FUNC: - { - const auto& v = id->GetVal(); + { + const auto& v = id->GetVal(); - if ( v && v->AsFunc()->GetBodies().size() == 1 ) - { - // Either a function or an event/hook with single body can - // report that single, continuous range. - loc = v->AsFunc()->GetBodies()[0].stmts->GetLocationInfo(); - ++extra_lines; - } - else - loc = id->GetLocationInfo(); + if ( v && v->AsFunc()->GetBodies().size() == 1 ) + { + // Either a function or an event/hook with single body can + // report that single, continuous range. + loc = v->AsFunc()->GetBodies()[0].stmts->GetLocationInfo(); + ++extra_lines; } + else + loc = id->GetLocationInfo(); + } break; case TYPE_ENUM: // Fallthrough From 9af6b2f48d11b4e287d0f18034a486f76f9f2d61 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Fri, 24 Sep 2021 16:06:13 -0700 Subject: [PATCH 7/7] clang-format: Set penalty for breaking after assignment operator --- .clang-format | 4 ++ src/DNS_Mgr.cc | 14 +++--- src/Dict.cc | 4 +- src/Discard.cc | 4 +- src/EventHandler.cc | 4 +- src/Expr.cc | 48 +++++++++---------- src/IP.cc | 4 +- src/NetVar.cc | 4 +- src/PrefixTable.cc | 4 +- src/Reporter.cc | 10 ++-- src/RuleMatcher.cc | 16 +++---- src/RunState.cc | 7 +-- src/Scope.cc | 4 +- src/Stats.cc | 14 +++--- src/Stmt.cc | 4 +- src/Timer.cc | 4 +- src/Type.cc | 16 +++---- src/Val.cc | 4 +- src/Val.h | 4 +- src/analyzer/protocol/dns/DNS.cc | 4 +- src/analyzer/protocol/http/HTTP.cc | 16 +++---- src/analyzer/protocol/mime/MIME.cc | 6 +-- src/analyzer/protocol/pia/PIA.cc | 8 ++-- src/analyzer/protocol/pop3/POP3.cc | 8 ++-- src/analyzer/protocol/rpc/RPC.cc | 4 +- src/analyzer/protocol/tcp/TCP_Reassembler.cc | 24 +++++----- src/broker/Data.cc | 4 +- src/broker/Manager.cc | 12 ++--- src/file_analysis/analyzer/x509/X509.cc | 8 ++-- src/file_analysis/analyzer/x509/X509Common.cc | 4 +- src/input/Manager.cc | 20 ++++---- src/input/readers/ascii/Ascii.cc | 4 +- src/input/readers/config/Config.cc | 4 +- src/input/readers/raw/Raw.cc | 12 ++--- src/logging/Manager.cc | 34 ++++++------- src/logging/WriterBackend.cc | 6 +-- src/logging/WriterBackend.h | 4 +- src/logging/writers/ascii/Ascii.cc | 20 ++++---- src/packet_analysis/protocol/icmp/ICMP.cc | 16 +++---- .../protocol/ip/IPBasedAnalyzer.cc | 8 ++-- .../protocol/tcp/TCPSessionAdapter.cc | 16 +++---- src/packet_analysis/protocol/udp/UDP.cc | 19 ++++---- src/plugin/ComponentManager.h | 4 +- src/probabilistic/BitVector.h | 4 +- src/script_opt/CPP/Exprs.cc | 4 +- src/script_opt/CPP/Inits.cc | 8 ++-- src/script_opt/Expr.cc | 4 +- src/script_opt/ZAM/Stmt.cc | 4 +- src/session/Manager.cc | 4 +- src/supervisor/Supervisor.cc | 4 +- src/telemetry/Manager.cc | 16 +++---- src/util.cc | 4 +- src/zeek-setup.cc | 8 ++-- src/zeekygen/PackageInfo.cc | 4 +- 54 files changed, 255 insertions(+), 247 deletions(-) diff --git a/.clang-format b/.clang-format index 79910187b2..a105b7df33 100644 --- a/.clang-format +++ b/.clang-format @@ -70,6 +70,10 @@ SpacesInParentheses: false TabWidth: 4 UseTab: AlignWithSpaces +# Setting this to a high number causes clang-format to prefer breaking somewhere else +# over breaking after the assignment operator in a line that's over the column limit +PenaltyBreakAssignment: 100 + IncludeBlocks: Regroup # Include categories go like this: diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index 408fda9f10..827f17ecfe 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -1167,16 +1167,16 @@ void DNS_Mgr::IssueAsyncRequests() if ( req->IsAddrReq() ) success = DoRequest(nb_dns, new DNS_Mgr_Request(req->host)); else if ( req->is_txt ) - success = - DoRequest(nb_dns, new DNS_Mgr_Request(req->name.c_str(), AF_INET, req->is_txt)); + success = DoRequest(nb_dns, + new DNS_Mgr_Request(req->name.c_str(), AF_INET, req->is_txt)); else { // If only one request type succeeds, don't consider it a failure. - success = - DoRequest(nb_dns, new DNS_Mgr_Request(req->name.c_str(), AF_INET, req->is_txt)); - success = - DoRequest(nb_dns, new DNS_Mgr_Request(req->name.c_str(), AF_INET6, req->is_txt)) || - success; + success = DoRequest(nb_dns, + new DNS_Mgr_Request(req->name.c_str(), AF_INET, req->is_txt)); + success = DoRequest(nb_dns, + new DNS_Mgr_Request(req->name.c_str(), AF_INET6, req->is_txt)) || + success; } if ( ! success ) diff --git a/src/Dict.cc b/src/Dict.cc index 3be737328a..62e4dd0d87 100644 --- a/src/Dict.cc +++ b/src/Dict.cc @@ -1060,8 +1060,8 @@ int Dictionary::LookupIndex(const void* key, int key_size, detail::hash_t hash, #ifdef DEBUG int linear_position = LinearLookupIndex(key, key_size, hash); #endif // DEBUG - int position = - LookupIndex(key, key_size, hash, bucket, Capacity(), insert_position, insert_distance); + int position = LookupIndex(key, key_size, hash, bucket, Capacity(), insert_position, + insert_distance); if ( position >= 0 ) { ASSERT(position == linear_position); // same as linearLookup diff --git a/src/Discard.cc b/src/Discard.cc index ba36754451..6f3d8b94ca 100644 --- a/src/Discard.cc +++ b/src/Discard.cc @@ -72,8 +72,8 @@ bool Discarder::NextPacket(const std::unique_ptr& ip, int len, int caple bool is_tcp = (proto == IPPROTO_TCP); bool is_udp = (proto == IPPROTO_UDP); - int min_hdr_len = - is_tcp ? sizeof(struct tcphdr) : (is_udp ? sizeof(struct udphdr) : sizeof(struct icmp)); + int min_hdr_len = is_tcp ? sizeof(struct tcphdr) + : (is_udp ? sizeof(struct udphdr) : sizeof(struct icmp)); if ( len < min_hdr_len || caplen < min_hdr_len ) // we don't have a complete protocol header diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 532dcc78e5..1196ae8ec8 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -32,8 +32,8 @@ const FuncTypePtr& EventHandler::GetType(bool check_export) if ( type ) return type; - const auto& id = - detail::lookup_ID(name.data(), detail::current_module.c_str(), false, false, check_export); + const auto& id = detail::lookup_ID(name.data(), detail::current_module.c_str(), false, false, + check_export); if ( ! id ) return FuncType::nil; diff --git a/src/Expr.cc b/src/Expr.cc index d12c023828..088c42f778 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -277,8 +277,8 @@ void Expr::AssignToIndex(ValPtr v1, ValPtr v2, ValPtr v3) const { bool iterators_invalidated; - auto error_msg = - assign_to_index(std::move(v1), std::move(v2), std::move(v3), iterators_invalidated); + auto error_msg = assign_to_index(std::move(v1), std::move(v2), std::move(v3), + iterators_invalidated); if ( iterators_invalidated ) { @@ -718,8 +718,8 @@ ValPtr UnaryExpr::Fold(Val* v) const void UnaryExpr::ExprDescribe(ODesc* d) const { - bool is_coerce = - Tag() == EXPR_ARITH_COERCE || Tag() == EXPR_RECORD_COERCE || Tag() == EXPR_TABLE_COERCE; + bool is_coerce = Tag() == EXPR_ARITH_COERCE || Tag() == EXPR_RECORD_COERCE || + Tag() == EXPR_TABLE_COERCE; if ( d->IsReadable() ) { @@ -1084,8 +1084,8 @@ ValPtr BinaryExpr::PatternFold(Val* v1, Val* v2) const if ( tag != EXPR_AND && tag != EXPR_OR ) BadTag("BinaryExpr::PatternFold"); - RE_Matcher* res = - tag == EXPR_AND ? RE_Matcher_conjunction(re1, re2) : RE_Matcher_disjunction(re1, re2); + RE_Matcher* res = tag == EXPR_AND ? RE_Matcher_conjunction(re1, re2) + : RE_Matcher_disjunction(re1, re2); return make_intrusive(res); } @@ -2860,9 +2860,9 @@ IndexExpr::IndexExpr(ExprPtr arg_op1, ListExprPtr arg_op2, bool arg_is_slice) if ( match_type == DOES_NOT_MATCH_INDEX ) { - std::string error_msg = - util::fmt("expression with type '%s' is not a type that can be indexed", - type_name(op1->GetType()->Tag())); + std::string error_msg = util::fmt( + "expression with type '%s' is not a type that can be indexed", + type_name(op1->GetType()->Tag())); SetError(error_msg.data()); } @@ -3995,8 +3995,8 @@ RecordCoerceExpr::RecordCoerceExpr(ExprPtr arg_op, RecordTypePtr r) if ( ! is_arithmetic_promotable(sup_t_i.get(), sub_t_i.get()) && ! is_record_promotable(sup_t_i.get(), sub_t_i.get()) ) { - std::string error_msg = - util::fmt("type clash for field \"%s\"", sub_r->FieldName(i)); + std::string error_msg = util::fmt("type clash for field \"%s\"", + sub_r->FieldName(i)); Error(error_msg.c_str(), sub_t_i.get()); SetError(); break; @@ -4015,8 +4015,8 @@ RecordCoerceExpr::RecordCoerceExpr(ExprPtr arg_op, RecordTypePtr r) { if ( ! t_r->FieldDecl(i)->GetAttr(ATTR_OPTIONAL) ) { - std::string error_msg = - util::fmt("non-optional field \"%s\" missing", t_r->FieldName(i)); + std::string error_msg = util::fmt("non-optional field \"%s\" missing", + t_r->FieldName(i)); Error(error_msg.c_str()); SetError(); break; @@ -4101,8 +4101,8 @@ RecordValPtr coerce_to_record(RecordTypePtr rt, Val* v, const std::vector& if ( rhs_type->Tag() == TYPE_RECORD && field_type->Tag() == TYPE_RECORD && ! same_type(rhs_type, field_type) ) { - if ( auto new_val = - rhs->AsRecordVal()->CoerceTo(cast_intrusive(field_type)) ) + if ( auto new_val = rhs->AsRecordVal()->CoerceTo( + cast_intrusive(field_type)) ) rhs = std::move(new_val); } else if ( BothArithmetic(rhs_type->Tag(), field_type->Tag()) && @@ -4125,8 +4125,8 @@ RecordValPtr coerce_to_record(RecordTypePtr rt, Val* v, const std::vector& if ( def_type->Tag() == TYPE_RECORD && field_type->Tag() == TYPE_RECORD && ! same_type(def_type, field_type) ) { - auto tmp = - def_val->AsRecordVal()->CoerceTo(cast_intrusive(field_type)); + auto tmp = def_val->AsRecordVal()->CoerceTo( + cast_intrusive(field_type)); if ( tmp ) def_val = std::move(tmp); @@ -4567,9 +4567,9 @@ LambdaExpr::LambdaExpr(std::unique_ptr arg_ing, IDPList ar // Install a dummy version of the function globally for use only // when broker provides a closure. - auto dummy_func = - make_intrusive(ingredients->id, ingredients->body, ingredients->inits, - ingredients->frame_size, ingredients->priority); + auto dummy_func = make_intrusive(ingredients->id, ingredients->body, + ingredients->inits, ingredients->frame_size, + ingredients->priority); dummy_func->SetOuterIDs(outer_ids); @@ -4880,8 +4880,8 @@ TypePtr ListExpr::InitType() const // Collapse any embedded sets or lists. if ( ti->IsSet() || ti->Tag() == TYPE_LIST ) { - TypeList* til = - ti->IsSet() ? ti->AsSetType()->GetIndices().get() : ti->AsTypeList(); + TypeList* til = ti->IsSet() ? ti->AsSetType()->GetIndices().get() + : ti->AsTypeList(); if ( ! til->IsPure() || ! til->AllMatch(til->GetPureType(), true) ) tl->Append({NewRef{}, til}); @@ -5164,8 +5164,8 @@ RecordAssignExpr::RecordAssignExpr(const ExprPtr& record, const ExprPtr& init_li if ( field >= 0 && same_type(lhs->GetFieldType(field), t->GetFieldType(j)) ) { auto fe_lhs = make_intrusive(record, field_name); - auto fe_rhs = - make_intrusive(IntrusivePtr{NewRef{}, init}, field_name); + auto fe_rhs = make_intrusive(IntrusivePtr{NewRef{}, init}, + field_name); Append(get_assign_expr(std::move(fe_lhs), std::move(fe_rhs), is_init)); } } diff --git a/src/IP.cc b/src/IP.cc index ba104277c4..04ac1b6676 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -656,8 +656,8 @@ void IPv6_Hdr_Chain::ProcessDstOpts(const struct ip6_dest* d, uint16_t len) if ( homeAddr ) reporter->Weird(SrcAddr(), DstAddr(), "multiple_home_addr_opts"); else - homeAddr = - new IPAddr(*((const in6_addr*)(data + sizeof(struct ip6_opt)))); + homeAddr = new IPAddr( + *((const in6_addr*)(data + sizeof(struct ip6_opt)))); } else reporter->Weird(SrcAddr(), DstAddr(), "bad_home_addr_len"); diff --git a/src/NetVar.cc b/src/NetVar.cc index 6f3acb2ad1..e9084f3085 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -292,8 +292,8 @@ void init_net_var() udp_content_deliver_all_orig = bool(id::find_val("udp_content_deliver_all_orig")->AsBool()); udp_content_deliver_all_resp = bool(id::find_val("udp_content_deliver_all_resp")->AsBool()); - udp_content_delivery_ports_use_resp = - bool(id::find_val("udp_content_delivery_ports_use_resp")->AsBool()); + udp_content_delivery_ports_use_resp = bool( + id::find_val("udp_content_delivery_ports_use_resp")->AsBool()); dns_session_timeout = id::find_val("dns_session_timeout")->AsInterval(); rpc_timeout = id::find_val("rpc_timeout")->AsInterval(); diff --git a/src/PrefixTable.cc b/src/PrefixTable.cc index 9c79db9c7d..ebb655182c 100644 --- a/src/PrefixTable.cc +++ b/src/PrefixTable.cc @@ -94,8 +94,8 @@ std::list> PrefixTable::FindAll(const SubNetVal* val void* PrefixTable::Lookup(const IPAddr& addr, int width, bool exact) const { prefix_t* prefix = MakePrefix(addr, width); - patricia_node_t* node = - exact ? patricia_search_exact(tree, prefix) : patricia_search_best(tree, prefix); + patricia_node_t* node = exact ? patricia_search_exact(tree, prefix) + : patricia_search_best(tree, prefix); int elems = 0; patricia_node_t** list = nullptr; diff --git a/src/Reporter.cc b/src/Reporter.cc index 33ff1be1ba..3bbb121208 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -600,11 +600,11 @@ void Reporter::DoLog(const char* prefix, EventHandlerPtr event, FILE* out, Conne if ( locations.size() ) { auto locs = locations.back(); - raise_event = - PLUGIN_HOOK_WITH_RESULT(HOOK_REPORTER, - HookReporter(prefix, event, conn, addl, location, - locs.first, locs.second, time, buffer), - true); + raise_event = PLUGIN_HOOK_WITH_RESULT(HOOK_REPORTER, + HookReporter(prefix, event, conn, addl, location, + locs.first, locs.second, time, + buffer), + true); } else raise_event = PLUGIN_HOOK_WITH_RESULT( diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index 9e00e3aa70..4cf0c15214 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -663,8 +663,8 @@ RuleMatcher::MIME_Matches* RuleMatcher::Match(RuleFileMagicState* state, const u #ifdef DEBUG if ( debug_logger.IsEnabled(DBG_RULES) ) { - const char* s = - util::fmt_bytes(reinterpret_cast(data), min(40, static_cast(len))); + const char* s = util::fmt_bytes(reinterpret_cast(data), + min(40, static_cast(len))); DBG_LOG(DBG_RULES, "Matching %s rules on |%s%s|", Rule::TypeToString(Rule::FILE_MAGIC), s, len > 40 ? "..." : ""); } @@ -806,8 +806,8 @@ RuleEndpointState* RuleMatcher::InitEndpoint(analyzer::Analyzer* analyzer, const case RuleHdrTest::ICMPv6: case RuleHdrTest::TCP: case RuleHdrTest::UDP: - match = - compare(*h->vals, getval(ip->Payload() + h->offset, h->size), h->comp); + match = compare(*h->vals, getval(ip->Payload() + h->offset, h->size), + h->comp); break; case RuleHdrTest::IPSrc: @@ -1405,8 +1405,8 @@ void RuleMatcherState::InitEndpointMatcher(analyzer::Analyzer* analyzer, const I delete orig_match_state; } - orig_match_state = - rule_matcher->InitEndpoint(analyzer, ip, caplen, resp_match_state, from_orig, pia); + orig_match_state = rule_matcher->InitEndpoint(analyzer, ip, caplen, resp_match_state, + from_orig, pia); } else @@ -1417,8 +1417,8 @@ void RuleMatcherState::InitEndpointMatcher(analyzer::Analyzer* analyzer, const I delete resp_match_state; } - resp_match_state = - rule_matcher->InitEndpoint(analyzer, ip, caplen, orig_match_state, from_orig, pia); + resp_match_state = rule_matcher->InitEndpoint(analyzer, ip, caplen, orig_match_state, + from_orig, pia); } } diff --git a/src/RunState.cc b/src/RunState.cc index 96bb7a5b2a..9852fc0744 100644 --- a/src/RunState.cc +++ b/src/RunState.cc @@ -386,9 +386,10 @@ void get_final_stats() { iosource::PktSrc::Stats s; ps->Statistics(&s); - double dropped_pct = - s.dropped > 0.0 ? ((double)s.dropped / ((double)s.received + (double)s.dropped)) * 100.0 - : 0.0; + double dropped_pct = s.dropped > 0.0 + ? ((double)s.dropped / ((double)s.received + (double)s.dropped)) * + 100.0 + : 0.0; reporter->Info("%" PRIu64 " packets received on interface %s, %" PRIu64 " (%.2f%%) dropped", s.received, ps->Path().c_str(), s.dropped, dropped_pct); } diff --git a/src/Scope.cc b/src/Scope.cc index ce8438bb44..896d84707d 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -111,8 +111,8 @@ const IDPtr& lookup_ID(const char* name, const char* curr_module, bool no_global std::string fullname = make_full_var_name(curr_module, name); std::string ID_module = extract_module_name(fullname.c_str()); - bool need_export = - check_export && (ID_module != GLOBAL_MODULE_NAME && ID_module != curr_module); + bool need_export = check_export && + (ID_module != GLOBAL_MODULE_NAME && ID_module != curr_module); for ( auto s_i = scopes.rbegin(); s_i != scopes.rend(); ++s_i ) { diff --git a/src/Stats.cc b/src/Stats.cc index cea561ee05..a428b934d7 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -392,13 +392,15 @@ void SegmentProfiler::Report() struct rusage final_rusage; getrusage(RUSAGE_SELF, &final_rusage); - double start_time = - double(initial_rusage.ru_utime.tv_sec) + double(initial_rusage.ru_utime.tv_usec) / 1e6 + - double(initial_rusage.ru_stime.tv_sec) + double(initial_rusage.ru_stime.tv_usec) / 1e6; + double start_time = double(initial_rusage.ru_utime.tv_sec) + + double(initial_rusage.ru_utime.tv_usec) / 1e6 + + double(initial_rusage.ru_stime.tv_sec) + + double(initial_rusage.ru_stime.tv_usec) / 1e6; - double stop_time = - double(final_rusage.ru_utime.tv_sec) + double(final_rusage.ru_utime.tv_usec) / 1e6 + - double(final_rusage.ru_stime.tv_sec) + double(final_rusage.ru_stime.tv_usec) / 1e6; + double stop_time = double(final_rusage.ru_utime.tv_sec) + + double(final_rusage.ru_utime.tv_usec) / 1e6 + + double(final_rusage.ru_stime.tv_sec) + + double(final_rusage.ru_stime.tv_usec) / 1e6; int start_mem = initial_rusage.ru_maxrss * 1024; int stop_mem = initial_rusage.ru_maxrss * 1024; diff --git a/src/Stmt.cc b/src/Stmt.cc index 257b2fd7a1..87c47d0adc 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -345,8 +345,8 @@ void do_print_stmt(const std::vector& vals) ++offset; } - static auto print_log_type = - static_cast(id::find_val("Log::print_to_log")->AsEnum()); + static auto print_log_type = static_cast( + id::find_val("Log::print_to_log")->AsEnum()); switch ( print_log_type ) { diff --git a/src/Timer.cc b/src/Timer.cc index 0bc71e072c..49b9624a43 100644 --- a/src/Timer.cc +++ b/src/Timer.cc @@ -103,8 +103,8 @@ void TimerMgr::Process() // Just advance the timer manager based on the current network time. This won't actually // change the time, but will dispatch any timers that need dispatching. - run_state::current_dispatched += - Advance(run_state::network_time, max_timer_expires - run_state::current_dispatched); + run_state::current_dispatched += Advance(run_state::network_time, + max_timer_expires - run_state::current_dispatched); } void TimerMgr::InitPostScript() diff --git a/src/Type.cc b/src/Type.cc index 7e04f80f74..d35378922b 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -520,8 +520,8 @@ TableType::TableType(TypeListPtr ind, TypePtr yield) if ( ! is_supported_index_type(tli, &unsupported_type_name) ) { - auto msg = - util::fmt("index type containing '%s' is not supported", unsupported_type_name); + auto msg = util::fmt("index type containing '%s' is not supported", + unsupported_type_name); Error(msg, tli.get()); SetError(); break; @@ -1720,8 +1720,8 @@ void EnumType::DescribeReST(ODesc* d, bool roles_only) const if ( doc->GetDeclaringScript() ) enum_from_script = doc->GetDeclaringScript()->Name(); - zeekygen::detail::IdentifierInfo* type_doc = - detail::zeekygen_mgr->GetIdentifierInfo(GetName()); + zeekygen::detail::IdentifierInfo* type_doc = detail::zeekygen_mgr->GetIdentifierInfo( + GetName()); if ( type_doc && type_doc->GetDeclaringScript() ) type_from_script = type_doc->GetDeclaringScript()->Name(); @@ -2310,10 +2310,10 @@ TypePtr merge_types(const TypePtr& arg_t1, const TypePtr& arg_t2) // actually see those changes from the redef. return id->GetType(); - std::string msg = - util::fmt("incompatible enum types: '%s' and '%s'" - " ('%s' enum type ID is invalid)", - t1->GetName().data(), t2->GetName().data(), t1->GetName().data()); + std::string msg = util::fmt("incompatible enum types: '%s' and '%s'" + " ('%s' enum type ID is invalid)", + t1->GetName().data(), t2->GetName().data(), + t1->GetName().data()); t1->Error(msg.data(), t2); return nullptr; } diff --git a/src/Val.cc b/src/Val.cc index 3fa01f64c1..305a638d83 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1839,8 +1839,8 @@ ValPtr TableVal::Default(const ValPtr& index) record_promotion_compatible(dtype->AsRecordType(), ytype->AsRecordType()) ) { auto rt = cast_intrusive(ytype); - auto coerce = - make_intrusive(def_attr->GetExpr(), std::move(rt)); + auto coerce = make_intrusive(def_attr->GetExpr(), + std::move(rt)); def_val = coerce->Eval(nullptr); } diff --git a/src/Val.h b/src/Val.h index 402a00d266..6ece8c90de 100644 --- a/src/Val.h +++ b/src/Val.h @@ -271,8 +271,8 @@ public: static constexpr bro_uint_t PREALLOCATED_COUNTS = 4096; static constexpr bro_uint_t PREALLOCATED_INTS = 512; static constexpr bro_int_t PREALLOCATED_INT_LOWEST = -255; - static constexpr bro_int_t PREALLOCATED_INT_HIGHEST = - PREALLOCATED_INT_LOWEST + PREALLOCATED_INTS - 1; + static constexpr bro_int_t PREALLOCATED_INT_HIGHEST = PREALLOCATED_INT_LOWEST + + PREALLOCATED_INTS - 1; ValManager(); diff --git a/src/analyzer/protocol/dns/DNS.cc b/src/analyzer/protocol/dns/DNS.cc index e34d0aa495..fe5424c00e 100644 --- a/src/analyzer/protocol/dns/DNS.cc +++ b/src/analyzer/protocol/dns/DNS.cc @@ -865,8 +865,8 @@ bool DNS_Interpreter::ParseRR_EDNS(detail::DNS_MsgInfo* msg, const u_char*& data if ( server_cookie_len >= 8 ) { - cookie.server_cookie = - ExtractStream(data, server_cookie_len, server_cookie_len); + cookie.server_cookie = ExtractStream(data, server_cookie_len, + server_cookie_len); } analyzer->EnqueueConnEvent(dns_EDNS_cookie, analyzer->ConnVal(), msg->BuildHdrVal(), diff --git a/src/analyzer/protocol/http/HTTP.cc b/src/analyzer/protocol/http/HTTP.cc index ff52cb5dab..e8c7b35a07 100644 --- a/src/analyzer/protocol/http/HTTP.cc +++ b/src/analyzer/protocol/http/HTTP.cc @@ -330,10 +330,10 @@ void HTTP_Entity::SubmitData(int len, const char* buf) else { if ( send_size && content_length > 0 ) - precomputed_file_id = - file_mgr->SetSize(content_length, http_message->MyHTTP_Analyzer()->GetAnalyzerTag(), - http_message->MyHTTP_Analyzer()->Conn(), http_message->IsOrig(), - precomputed_file_id); + precomputed_file_id = file_mgr->SetSize( + content_length, http_message->MyHTTP_Analyzer()->GetAnalyzerTag(), + http_message->MyHTTP_Analyzer()->Conn(), http_message->IsOrig(), + precomputed_file_id); precomputed_file_id = file_mgr->DataIn(reinterpret_cast(buf), len, http_message->MyHTTP_Analyzer()->GetAnalyzerTag(), @@ -894,8 +894,8 @@ void HTTP_Analyzer::DeliverStream(int len, const u_char* data, bool is_orig) const char* line = reinterpret_cast(data); const char* end_of_line = line + len; - analyzer::tcp::ContentLine_Analyzer* content_line = - is_orig ? content_line_orig : content_line_resp; + analyzer::tcp::ContentLine_Analyzer* content_line = is_orig ? content_line_orig + : content_line_resp; if ( content_line->IsPlainDelivery() ) { @@ -1063,8 +1063,8 @@ void HTTP_Analyzer::Undelivered(uint64_t seq, int len, bool is_orig) HTTP_Message* msg = is_orig ? request_message : reply_message; - analyzer::tcp::ContentLine_Analyzer* content_line = - is_orig ? content_line_orig : content_line_resp; + analyzer::tcp::ContentLine_Analyzer* content_line = is_orig ? content_line_orig + : content_line_resp; if ( ! content_line->IsSkippedContents(seq, len) ) { diff --git a/src/analyzer/protocol/mime/MIME.cc b/src/analyzer/protocol/mime/MIME.cc index 5762803a49..00517beac7 100644 --- a/src/analyzer/protocol/mime/MIME.cc +++ b/src/analyzer/protocol/mime/MIME.cc @@ -1461,9 +1461,9 @@ void MIME_Mail::SubmitData(int len, const char* buf) make_intrusive(data_len, data)); } - cur_entity_id = - file_mgr->DataIn(reinterpret_cast(buf), len, analyzer->GetAnalyzerTag(), - analyzer->Conn(), is_orig, cur_entity_id); + cur_entity_id = file_mgr->DataIn(reinterpret_cast(buf), len, + analyzer->GetAnalyzerTag(), analyzer->Conn(), is_orig, + cur_entity_id); cur_entity_len += len; buffer_start = (buf + len) - (char*)data_buffer->Bytes(); diff --git a/src/analyzer/protocol/pia/PIA.cc b/src/analyzer/protocol/pia/PIA.cc index 93a4cbc677..a4314294c1 100644 --- a/src/analyzer/protocol/pia/PIA.cc +++ b/src/analyzer/protocol/pia/PIA.cc @@ -382,11 +382,11 @@ void PIA_TCP::ActivateAnalyzer(analyzer::Tag tag, const zeek::detail::Rule* rule auto* tcp = static_cast(Parent()); - auto* reass_orig = - new tcp::TCP_Reassembler(this, tcp, tcp::TCP_Reassembler::Direct, tcp->Orig()); + auto* reass_orig = new tcp::TCP_Reassembler(this, tcp, tcp::TCP_Reassembler::Direct, + tcp->Orig()); - auto* reass_resp = - new tcp::TCP_Reassembler(this, tcp, tcp::TCP_Reassembler::Direct, tcp->Resp()); + auto* reass_resp = new tcp::TCP_Reassembler(this, tcp, tcp::TCP_Reassembler::Direct, + tcp->Resp()); uint64_t orig_seq = 0; uint64_t resp_seq = 0; diff --git a/src/analyzer/protocol/pop3/POP3.cc b/src/analyzer/protocol/pop3/POP3.cc index 4054c3ffb2..3d13701933 100644 --- a/src/analyzer/protocol/pop3/POP3.cc +++ b/src/analyzer/protocol/pop3/POP3.cc @@ -585,10 +585,10 @@ void POP3_Analyzer::ProcessReply(int length, const char* line) if ( multiLine == true ) { - bool terminator = - line[0] == '.' && - (length == 1 || (length > 1 && (line[1] == '\n' || - (length > 2 && line[1] == '\r' && line[2] == '\n')))); + bool terminator = line[0] == '.' && + (length == 1 || + (length > 1 && (line[1] == '\n' || + (length > 2 && line[1] == '\r' && line[2] == '\n')))); if ( terminator ) { diff --git a/src/analyzer/protocol/rpc/RPC.cc b/src/analyzer/protocol/rpc/RPC.cc index f8bef3a887..f169ea7854 100644 --- a/src/analyzer/protocol/rpc/RPC.cc +++ b/src/analyzer/protocol/rpc/RPC.cc @@ -69,8 +69,8 @@ RPC_CallInfo::RPC_CallInfo(uint32_t arg_xid, const u_char*& buf, int& n, double stamp = extract_XDR_uint32(cred_opaque, cred_opaque_n); int machinename_n; constexpr auto max_machinename_len = 255; - auto mnp = - extract_XDR_opaque(cred_opaque, cred_opaque_n, machinename_n, max_machinename_len); + auto mnp = extract_XDR_opaque(cred_opaque, cred_opaque_n, machinename_n, + max_machinename_len); if ( ! mnp ) { diff --git a/src/analyzer/protocol/tcp/TCP_Reassembler.cc b/src/analyzer/protocol/tcp/TCP_Reassembler.cc index fb1323a2c6..7c521f7bfd 100644 --- a/src/analyzer/protocol/tcp/TCP_Reassembler.cc +++ b/src/analyzer/protocol/tcp/TCP_Reassembler.cc @@ -42,14 +42,14 @@ TCP_Reassembler::TCP_Reassembler(analyzer::Analyzer* arg_dst_analyzer, if ( ::tcp_contents ) { - static auto tcp_content_delivery_ports_orig = - id::find_val("tcp_content_delivery_ports_orig"); - static auto tcp_content_delivery_ports_resp = - id::find_val("tcp_content_delivery_ports_resp"); - const auto& dst_port_val = - val_mgr->Port(ntohs(tcp_analyzer->Conn()->RespPort()), TRANSPORT_TCP); - const auto& ports = - IsOrig() ? tcp_content_delivery_ports_orig : tcp_content_delivery_ports_resp; + static auto tcp_content_delivery_ports_orig = id::find_val( + "tcp_content_delivery_ports_orig"); + static auto tcp_content_delivery_ports_resp = id::find_val( + "tcp_content_delivery_ports_resp"); + const auto& dst_port_val = val_mgr->Port(ntohs(tcp_analyzer->Conn()->RespPort()), + TRANSPORT_TCP); + const auto& ports = IsOrig() ? tcp_content_delivery_ports_orig + : tcp_content_delivery_ports_resp; auto result = ports->FindOrDefault(dst_port_val); if ( (IsOrig() && zeek::detail::tcp_content_deliver_all_orig) || @@ -519,10 +519,10 @@ void TCP_Reassembler::AckReceived(uint64_t seq) // Nothing to do. return; - bool test_active = - ! skip_deliveries && ! tcp_analyzer->Skipping() && - (BifConst::report_gaps_for_partial || (endp->state == TCP_ENDPOINT_ESTABLISHED && - endp->peer->state == TCP_ENDPOINT_ESTABLISHED)); + bool test_active = ! skip_deliveries && ! tcp_analyzer->Skipping() && + (BifConst::report_gaps_for_partial || + (endp->state == TCP_ENDPOINT_ESTABLISHED && + endp->peer->state == TCP_ENDPOINT_ESTABLISHED)); uint64_t num_missing = TrimToSeq(seq); diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 8045edb6b7..80651fc822 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -364,8 +364,8 @@ struct val_converter unsigned int pos = 0; for ( auto& item : a ) { - auto item_val = - data_to_val(move(item), pure ? lt->GetPureType().get() : types[pos].get()); + auto item_val = data_to_val(move(item), + pure ? lt->GetPureType().get() : types[pos].get()); pos++; if ( ! item_val ) diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 65a70c4316..d4a8445c37 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -376,8 +376,8 @@ void Manager::InitializeBrokerStoreForwarding() if ( id->HasVal() && id->GetAttr(zeek::detail::ATTR_BACKEND) ) { const auto& attr = id->GetAttr(zeek::detail::ATTR_BACKEND); - auto e = - static_cast(attr->GetExpr()->Eval(nullptr)->AsEnum()); + auto e = static_cast( + attr->GetExpr()->Eval(nullptr)->AsEnum()); auto storename = std::string("___sync_store_") + global.first; id->GetVal()->AsTableVal()->SetBrokerStore(storename); AddForwardedStore(storename, cast_intrusive(id->GetVal())); @@ -739,8 +739,8 @@ bool Manager::PublishLogWrite(EnumVal* stream, EnumVal* writer, string path, int std::string serial_data(data, len); free(data); - auto v = - log_topic_func->Invoke(IntrusivePtr{NewRef{}, stream}, make_intrusive(path)); + auto v = log_topic_func->Invoke(IntrusivePtr{NewRef{}, stream}, + make_intrusive(path)); if ( ! v ) { @@ -1797,8 +1797,8 @@ void Manager::BrokerStoreToZeekTable(const std::string& name, const detail::Stor if ( its.size() == 1 ) zeek_key = detail::data_to_val(key, its[0].get()); else - zeek_key = - detail::data_to_val(key, table->GetType()->AsTableType()->GetIndices().get()); + zeek_key = detail::data_to_val(key, + table->GetType()->AsTableType()->GetIndices().get()); if ( ! zeek_key ) { diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index 20e43514eb..2851c241ce 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -177,8 +177,8 @@ RecordValPtr X509::ParseCertificate(X509Val* cert_val, file_analysis::File* f) if ( OBJ_obj2nid(algorithm) == NID_md5WithRSAEncryption ) { - ASN1_OBJECT* copy = - OBJ_dup(algorithm); // the next line will destroy the original algorithm. + ASN1_OBJECT* copy = OBJ_dup( + algorithm); // the next line will destroy the original algorithm. X509_PUBKEY_set0_param(X509_get_X509_PUBKEY(ssl_cert), OBJ_nid2obj(NID_rsaEncryption), 0, NULL, NULL, 0); algorithm = copy; @@ -288,8 +288,8 @@ void X509::ParseBasicConstraints(X509_EXTENSION* ex) { if ( x509_ext_basic_constraints ) { - auto pBasicConstraint = - make_intrusive(BifType::Record::X509::BasicConstraints); + auto pBasicConstraint = make_intrusive( + BifType::Record::X509::BasicConstraints); pBasicConstraint->Assign(0, constr->ca); if ( constr->pathlen ) diff --git a/src/file_analysis/analyzer/x509/X509Common.cc b/src/file_analysis/analyzer/x509/X509Common.cc index afbedbf36b..57c74965a7 100644 --- a/src/file_analysis/analyzer/x509/X509Common.cc +++ b/src/file_analysis/analyzer/x509/X509Common.cc @@ -205,8 +205,8 @@ void X509Common::ParseSignedCertificateTimestamps(X509_EXTENSION* ext) unsigned char* ext_val_second_pointer = ext_val_copy; memcpy(ext_val_copy, ext_val->data, ext_val->length); - ASN1_OCTET_STRING* inner = - d2i_ASN1_OCTET_STRING(NULL, (const unsigned char**)&ext_val_copy, ext_val->length); + ASN1_OCTET_STRING* inner = d2i_ASN1_OCTET_STRING(NULL, (const unsigned char**)&ext_val_copy, + ext_val->length); if ( ! inner ) { reporter->Error( diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 2869bfb9d2..d8c389cef6 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1179,8 +1179,8 @@ int Manager::SendEntryTable(Stream* i, const Value* const* vals) zeek::detail::hash_t valhash = 0; if ( stream->num_val_fields > 0 ) { - if ( zeek::detail::HashKey* valhashkey = - HashValues(stream->num_val_fields, vals + stream->num_idx_fields) ) + if ( zeek::detail::HashKey* valhashkey = HashValues(stream->num_val_fields, + vals + stream->num_idx_fields) ) { valhash = valhashkey->Hash(); delete (valhashkey); @@ -1681,8 +1681,8 @@ int Manager::PutTable(Stream* i, const Value* const* vals) { // in case of update send back the old value. assert(stream->num_val_fields > 0); - auto ev = - BifType::Enum::Input::Event->GetEnumVal(BifEnum::Input::EVENT_CHANGED); + auto ev = BifType::Enum::Input::Event->GetEnumVal( + BifEnum::Input::EVENT_CHANGED); assert(oldval != nullptr); SendEvent(stream->event, 4, stream->description->Ref(), ev.release(), predidx, oldval.release()); @@ -1746,8 +1746,8 @@ bool Manager::Delete(ReaderFrontend* reader, Value** vals) { TableStream* stream = (TableStream*)i; bool convert_error = false; - Val* idxval = - ValueToIndexVal(i, stream->num_idx_fields, stream->itype, vals, convert_error); + Val* idxval = ValueToIndexVal(i, stream->num_idx_fields, stream->itype, vals, + convert_error); readVals = stream->num_idx_fields + stream->num_val_fields; bool streamresult = true; @@ -1772,8 +1772,8 @@ bool Manager::Delete(ReaderFrontend* reader, Value** vals) Unref(predidx); else { - auto ev = - BifType::Enum::Input::Event->GetEnumVal(BifEnum::Input::EVENT_REMOVED); + auto ev = BifType::Enum::Input::Event->GetEnumVal( + BifEnum::Input::EVENT_REMOVED); streamresult = CallPred(stream->pred, 3, ev.release(), predidx, IntrusivePtr{val}.release()); @@ -1906,8 +1906,8 @@ RecordVal* Manager::ListValToRecordVal(ListVal* list, RecordType* request_type, Val* fieldVal = nullptr; if ( request_type->GetFieldType(i)->Tag() == TYPE_RECORD ) - fieldVal = - ListValToRecordVal(list, request_type->GetFieldType(i)->AsRecordType(), position); + fieldVal = ListValToRecordVal(list, request_type->GetFieldType(i)->AsRecordType(), + position); else { fieldVal = list->Idx(*position).get(); diff --git a/src/input/readers/ascii/Ascii.cc b/src/input/readers/ascii/Ascii.cc index 2a001f04fa..0c78dc4eb1 100644 --- a/src/input/readers/ascii/Ascii.cc +++ b/src/input/readers/ascii/Ascii.cc @@ -419,8 +419,8 @@ bool Ascii::DoUpdate() assert(val->type == TYPE_PORT); // Error(Fmt("Got type %d != PORT with secondary position!", val->type)); - val->val.port_val.proto = - formatter->ParseProto(stringfields[(*fit).secondary_position]); + val->val.port_val.proto = formatter->ParseProto( + stringfields[(*fit).secondary_position]); } fields[fpos] = val; diff --git a/src/input/readers/config/Config.cc b/src/input/readers/config/Config.cc index 011498f059..fb5201fcf0 100644 --- a/src/input/readers/config/Config.cc +++ b/src/input/readers/config/Config.cc @@ -69,8 +69,8 @@ bool Config::DoInit(const ReaderInfo& info, int num_fields, const Field* const* BifConst::InputConfig::empty_field->Len()); threading::formatter::Ascii::SeparatorInfo sep_info("\t", set_separator, "", empty_field); - formatter = - std::unique_ptr(new threading::formatter::Ascii(this, sep_info)); + formatter = std::unique_ptr( + new threading::formatter::Ascii(this, sep_info)); return DoUpdate(); } diff --git a/src/input/readers/raw/Raw.cc b/src/input/readers/raw/Raw.cc index 1d938f6be4..463f4d6a2d 100644 --- a/src/input/readers/raw/Raw.cc +++ b/src/input/readers/raw/Raw.cc @@ -256,8 +256,8 @@ bool Raw::Execute() if ( use_stderr ) { - stderrfile = - std::unique_ptr(fdopen(pipes[stderr_in], "r"), fclose); + stderrfile = std::unique_ptr(fdopen(pipes[stderr_in], "r"), + fclose); if ( ! stderrfile ) { @@ -359,8 +359,8 @@ bool Raw::DoInit(const ReaderInfo& info, int num_fields, const Field* const* fie fname = source.substr(0, fname.length() - 1); } - ReaderInfo::config_map::const_iterator it = - info.config.find("stdin"); // data that is sent to the child process + ReaderInfo::config_map::const_iterator it = info.config.find( + "stdin"); // data that is sent to the child process if ( it != info.config.end() ) { stdin_string = it->second; @@ -486,8 +486,8 @@ int64_t Raw::GetLine(FILE* arg_file) repeats++; // bah, we cannot use realloc because we would have to change the delete in the manager // to a free. - std::unique_ptr newbuf = - std::unique_ptr(new char[block_size * repeats]); + std::unique_ptr newbuf = std::unique_ptr( + new char[block_size * repeats]); memcpy(newbuf.get(), buf.get(), block_size * (repeats - 1)); buf = std::move(newbuf); offset = block_size * (repeats - 1); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 8cd1adc099..a50c1d8952 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -526,8 +526,8 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, Tab bool optional = (bool)rtype->FieldDecl(i)->GetAttr(detail::ATTR_OPTIONAL); - filter->fields[filter->num_fields - 1] = - new threading::Field(new_path.c_str(), nullptr, t->Tag(), st, optional); + filter->fields[filter->num_fields - 1] = new threading::Field(new_path.c_str(), nullptr, + t->Tag(), st, optional); } return true; @@ -868,8 +868,8 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) if ( const auto& val = filter->field_name_map->Find(fn) ) { delete[] filter->fields[j]->name; - filter->fields[j]->name = - util::copy_string(val->AsStringVal()->CheckString()); + filter->fields[j]->name = util::copy_string( + val->AsStringVal()->CheckString()); } } arg_fields[j] = new threading::Field(*filter->fields[j]); @@ -1049,8 +1049,8 @@ threading::Value* Manager::ValToLogVal(Val* val, Type* ty) for ( bro_int_t i = 0; i < lval->val.vector_val.size; i++ ) { - lval->val.vector_val.vals[i] = - ValToLogVal(vec->ValAt(i).get(), vec->GetType()->Yield().get()); + lval->val.vector_val.vals[i] = ValToLogVal(vec->ValAt(i).get(), + vec->GetType()->Yield().get()); } break; @@ -1153,8 +1153,8 @@ WriterFrontend* Manager::CreateWriter(EnumVal* id, EnumVal* writer, WriterBacken return nullptr; } - Stream::WriterMap::iterator w = - stream->writers.find(Stream::WriterPathPair(writer->AsEnum(), info->path)); + Stream::WriterMap::iterator w = stream->writers.find( + Stream::WriterPathPair(writer->AsEnum(), info->path)); if ( w != stream->writers.end() ) { @@ -1279,8 +1279,8 @@ bool Manager::WriteFromRemote(EnumVal* id, EnumVal* writer, const string& path, return true; } - Stream::WriterMap::iterator w = - stream->writers.find(Stream::WriterPathPair(writer->AsEnum(), path)); + Stream::WriterMap::iterator w = stream->writers.find( + Stream::WriterPathPair(writer->AsEnum(), path)); if ( w == stream->writers.end() ) { @@ -1478,11 +1478,11 @@ void Manager::InstallRotationTimer(WriterInfo* winfo) static auto base_time = log_rotate_base_time->AsString()->CheckString(); double base = util::detail::parse_rotate_base_time(base_time); - double delta_t = - util::detail::calc_next_rotate(run_state::network_time, rotation_interval, base); + double delta_t = util::detail::calc_next_rotate(run_state::network_time, + rotation_interval, base); - winfo->rotation_timer = - new RotationTimer(run_state::network_time + delta_t, winfo, true); + winfo->rotation_timer = new RotationTimer(run_state::network_time + delta_t, winfo, + true); } zeek::detail::timer_mgr->Add(winfo->rotation_timer); @@ -1561,9 +1561,9 @@ void Manager::Rotate(WriterInfo* winfo) else ppf = default_ppf; - auto rotation_path = - FormatRotationPath({NewRef{}, winfo->type}, winfo->writer->Info().path, winfo->open_time, - run_state::network_time, run_state::terminating, std::move(ppf)); + auto rotation_path = FormatRotationPath({NewRef{}, winfo->type}, winfo->writer->Info().path, + winfo->open_time, run_state::network_time, + run_state::terminating, std::move(ppf)); winfo->writer->Rotate(rotation_path.data(), winfo->open_time, run_state::network_time, run_state::terminating); diff --git a/src/logging/WriterBackend.cc b/src/logging/WriterBackend.cc index 54246cbd96..33c8d5e23c 100644 --- a/src/logging/WriterBackend.cc +++ b/src/logging/WriterBackend.cc @@ -239,9 +239,9 @@ bool WriterBackend::Write(int arg_num_fields, int num_writes, Value*** vals) if ( vals[j][i]->type != fields[i]->type ) { #ifdef DEBUG - const char* msg = - Fmt("Field #%d type doesn't match in WriterBackend::Write() (%d vs. %d)", i, - vals[j][i]->type, fields[i]->type); + const char* msg = Fmt( + "Field #%d type doesn't match in WriterBackend::Write() (%d vs. %d)", i, + vals[j][i]->type, fields[i]->type); Debug(DBG_LOGGING, msg); #endif DisableFrontend(); diff --git a/src/logging/WriterBackend.h b/src/logging/WriterBackend.h index 10035c1cbb..b3397c49ca 100644 --- a/src/logging/WriterBackend.h +++ b/src/logging/WriterBackend.h @@ -101,8 +101,8 @@ public: WriterInfo(const WriterInfo& other) { path = other.path ? util::copy_string(other.path) : nullptr; - post_proc_func = - other.post_proc_func ? util::copy_string(other.post_proc_func) : nullptr; + post_proc_func = other.post_proc_func ? util::copy_string(other.post_proc_func) + : nullptr; rotation_interval = other.rotation_interval; rotation_base = other.rotation_base; network_time = other.network_time; diff --git a/src/logging/writers/ascii/Ascii.cc b/src/logging/writers/ascii/Ascii.cc index c0c7758326..a53464f925 100644 --- a/src/logging/writers/ascii/Ascii.cc +++ b/src/logging/writers/ascii/Ascii.cc @@ -105,8 +105,8 @@ static std::optional parse_shadow_log(const std::string& fname) if ( ! sf_stream ) { - rval.error = - util::fmt("Failed to open %s: %s", rval.shadow_filename.data(), strerror(errno)); + rval.error = util::fmt("Failed to open %s: %s", rval.shadow_filename.data(), + strerror(errno)); return rval; } @@ -124,8 +124,8 @@ static std::optional parse_shadow_log(const std::string& fname) if ( sf_len == -1 ) { - rval.error = - util::fmt("Failed to ftell() on %s: %s", rval.shadow_filename.data(), strerror(errno)); + rval.error = util::fmt("Failed to ftell() on %s: %s", rval.shadow_filename.data(), + strerror(errno)); fclose(sf_stream); return rval; } @@ -169,8 +169,8 @@ static std::optional parse_shadow_log(const std::string& fname) // Use shadow file's modification time as creation time. if ( stat(rval.shadow_filename.data(), &st) != 0 ) { - rval.error = - util::fmt("Failed to stat %s: %s", rval.shadow_filename.data(), strerror(errno)); + rval.error = util::fmt("Failed to stat %s: %s", rval.shadow_filename.data(), + strerror(errno)); return rval; } @@ -454,8 +454,8 @@ bool Ascii::DoInit(const WriterInfo& info, int num_fields, const threading::Fiel fname += ext; - bool use_shadow = - BifConst::LogAscii::enable_leftover_log_rotation && Info().rotation_interval > 0; + bool use_shadow = BifConst::LogAscii::enable_leftover_log_rotation && + Info().rotation_interval > 0; if ( use_shadow ) { @@ -676,8 +676,8 @@ bool Ascii::DoRotate(const char* rotated_path, double open, double close, bool t return false; } - bool use_shadow = - BifConst::LogAscii::enable_leftover_log_rotation && Info().rotation_interval > 0; + bool use_shadow = BifConst::LogAscii::enable_leftover_log_rotation && + Info().rotation_interval > 0; if ( use_shadow ) { diff --git a/src/packet_analysis/protocol/icmp/ICMP.cc b/src/packet_analysis/protocol/icmp/ICMP.cc index 4913859b18..18a89c16fb 100644 --- a/src/packet_analysis/protocol/icmp/ICMP.cc +++ b/src/packet_analysis/protocol/icmp/ICMP.cc @@ -49,11 +49,11 @@ bool ICMPAnalyzer::BuildConnTuple(size_t len, const uint8_t* data, Packet* packe tuple.src_port = htons(icmpp->icmp_type); if ( packet->proto == IPPROTO_ICMP ) - tuple.dst_port = - htons(ICMP4_counterpart(icmpp->icmp_type, icmpp->icmp_code, tuple.is_one_way)); + tuple.dst_port = htons( + ICMP4_counterpart(icmpp->icmp_type, icmpp->icmp_code, tuple.is_one_way)); else if ( packet->proto == IPPROTO_ICMPV6 ) - tuple.dst_port = - htons(ICMP6_counterpart(icmpp->icmp_type, icmpp->icmp_code, tuple.is_one_way)); + tuple.dst_port = htons( + ICMP6_counterpart(icmpp->icmp_type, icmpp->icmp_code, tuple.is_one_way)); else reporter->InternalError("Reached ICMP packet analyzer with unknown packet protocol %x", packet->proto); @@ -280,11 +280,11 @@ TransportProto ICMPAnalyzer::GetContextProtocol(const IP_Hdr* ip_hdr, uint32_t* *src_port = ntohs(icmpp->icmp_type); if ( ip4 ) - *dst_port = - ntohs(ICMP4_counterpart(icmpp->icmp_type, icmpp->icmp_code, is_one_way)); + *dst_port = ntohs( + ICMP4_counterpart(icmpp->icmp_type, icmpp->icmp_code, is_one_way)); else - *dst_port = - ntohs(ICMP6_counterpart(icmpp->icmp_type, icmpp->icmp_code, is_one_way)); + *dst_port = ntohs( + ICMP6_counterpart(icmpp->icmp_type, icmpp->icmp_code, is_one_way)); break; } diff --git a/src/packet_analysis/protocol/ip/IPBasedAnalyzer.cc b/src/packet_analysis/protocol/ip/IPBasedAnalyzer.cc index 193fb6958c..785d914498 100644 --- a/src/packet_analysis/protocol/ip/IPBasedAnalyzer.cc +++ b/src/packet_analysis/protocol/ip/IPBasedAnalyzer.cc @@ -160,8 +160,8 @@ zeek::Connection* IPBasedAnalyzer::NewConn(const ConnTuple* id, const detail::Co if ( ! WantConnection(src_h, dst_h, pkt->ip_hdr->Payload(), flip) ) return nullptr; - Connection* conn = - new Connection(key, run_state::processing_start_time, id, pkt->ip_hdr->FlowLabel(), pkt); + Connection* conn = new Connection(key, run_state::processing_start_time, id, + pkt->ip_hdr->FlowLabel(), pkt); conn->SetTransport(transport); if ( flip ) @@ -293,7 +293,7 @@ void IPBasedAnalyzer::SetIgnoreChecksumsNets(TableValPtr t) TableValPtr IPBasedAnalyzer::GetIgnoreChecksumsNets() { if ( ! IPBasedAnalyzer::ignore_checksums_nets_table ) - IPBasedAnalyzer::ignore_checksums_nets_table = - zeek::id::find_val("ignore_checksums_nets"); + IPBasedAnalyzer::ignore_checksums_nets_table = zeek::id::find_val( + "ignore_checksums_nets"); return IPBasedAnalyzer::ignore_checksums_nets_table; } diff --git a/src/packet_analysis/protocol/tcp/TCPSessionAdapter.cc b/src/packet_analysis/protocol/tcp/TCPSessionAdapter.cc index 80c1e68235..a563650b74 100644 --- a/src/packet_analysis/protocol/tcp/TCPSessionAdapter.cc +++ b/src/packet_analysis/protocol/tcp/TCPSessionAdapter.cc @@ -636,8 +636,8 @@ void TCPSessionAdapter::Process(bool is_orig, const struct tcphdr* tp, int len, else { bool ack_underflow = false; - rel_ack = - get_relative_seq(peer, ack_seq, peer->AckSeq(), peer->AckWraps(), &ack_underflow); + rel_ack = get_relative_seq(peer, ack_seq, peer->AckSeq(), peer->AckWraps(), + &ack_underflow); if ( ack_underflow ) { @@ -1614,10 +1614,10 @@ void TCPSessionAdapter::AddExtraAnalyzers(Connection* conn) if ( tcp_contents && ! reass ) { - static auto tcp_content_delivery_ports_orig = - id::find_val("tcp_content_delivery_ports_orig"); - static auto tcp_content_delivery_ports_resp = - id::find_val("tcp_content_delivery_ports_resp"); + static auto tcp_content_delivery_ports_orig = id::find_val( + "tcp_content_delivery_ports_orig"); + static auto tcp_content_delivery_ports_resp = id::find_val( + "tcp_content_delivery_ports_resp"); const auto& dport = val_mgr->Port(ntohs(Conn()->RespPort()), TRANSPORT_TCP); if ( ! reass ) @@ -1821,8 +1821,8 @@ int TCPSessionAdapter::ParseTCPOptions(const struct tcphdr* tcp, bool is_orig) void TCPSessionAdapter::CheckRecording(bool need_contents, analyzer::tcp::TCP_Flags flags) { bool record_current_content = need_contents || Conn()->RecordContents(); - bool record_current_packet = - Conn()->RecordPackets() || flags.SYN() || flags.FIN() || flags.RST(); + bool record_current_packet = Conn()->RecordPackets() || flags.SYN() || flags.FIN() || + flags.RST(); Conn()->SetRecordCurrentContent(record_current_content); Conn()->SetRecordCurrentPacket(record_current_packet); diff --git a/src/packet_analysis/protocol/udp/UDP.cc b/src/packet_analysis/protocol/udp/UDP.cc index 50c9f32a2b..374f69c50c 100644 --- a/src/packet_analysis/protocol/udp/UDP.cc +++ b/src/packet_analysis/protocol/udp/UDP.cc @@ -102,9 +102,10 @@ void UDPAnalyzer::DeliverPacket(Connection* c, double t, bool is_orig, int remai int chksum = up->uh_sum; - auto validate_checksum = - ! run_state::current_pkt->l3_checksummed && ! zeek::detail::ignore_checksums && - ! GetIgnoreChecksumsNets()->Contains(ip->IPHeaderSrcAddr()) && remaining >= len; + auto validate_checksum = ! run_state::current_pkt->l3_checksummed && + ! zeek::detail::ignore_checksums && + ! GetIgnoreChecksumsNets()->Contains(ip->IPHeaderSrcAddr()) && + remaining >= len; constexpr auto vxlan_len = 8; constexpr auto eth_len = 14; @@ -159,10 +160,10 @@ void UDPAnalyzer::DeliverPacket(Connection* c, double t, bool is_orig, int remai if ( udp_contents ) { static auto udp_content_ports = id::find_val("udp_content_ports"); - static auto udp_content_delivery_ports_orig = - id::find_val("udp_content_delivery_ports_orig"); - static auto udp_content_delivery_ports_resp = - id::find_val("udp_content_delivery_ports_resp"); + static auto udp_content_delivery_ports_orig = id::find_val( + "udp_content_delivery_ports_orig"); + static auto udp_content_delivery_ports_resp = id::find_val( + "udp_content_delivery_ports_resp"); bool do_udp_contents = false; const auto& sport_val = val_mgr->Port(ntohs(up->uh_sport), TRANSPORT_UDP); const auto& dport_val = val_mgr->Port(ntohs(up->uh_dport), TRANSPORT_UDP); @@ -172,8 +173,8 @@ void UDPAnalyzer::DeliverPacket(Connection* c, double t, bool is_orig, int remai do_udp_contents = true; else { - uint16_t p = - zeek::detail::udp_content_delivery_ports_use_resp ? c->RespPort() : up->uh_dport; + uint16_t p = zeek::detail::udp_content_delivery_ports_use_resp ? c->RespPort() + : up->uh_dport; const auto& port_val = zeek::val_mgr->Port(ntohs(p), TRANSPORT_UDP); if ( is_orig ) diff --git a/src/plugin/ComponentManager.h b/src/plugin/ComponentManager.h index a59326077c..a1bb6d80be 100644 --- a/src/plugin/ComponentManager.h +++ b/src/plugin/ComponentManager.h @@ -193,8 +193,8 @@ template T ComponentManager::GetComponentTag(Val* v) co template C* ComponentManager::Lookup(const std::string& name) const { - typename std::map::const_iterator i = - components_by_name.find(util::to_upper(name)); + typename std::map::const_iterator i = components_by_name.find( + util::to_upper(name)); return i != components_by_name.end() ? i->second : 0; } diff --git a/src/probabilistic/BitVector.h b/src/probabilistic/BitVector.h index ca4f0f238e..3f4c94e9e9 100644 --- a/src/probabilistic/BitVector.h +++ b/src/probabilistic/BitVector.h @@ -135,8 +135,8 @@ public: return; block_type excess = extra_bits(); - typename std::iterator_traits::difference_type delta = - std::distance(first, last); + typename std::iterator_traits::difference_type delta = std::distance(first, + last); bits.reserve(Blocks() + delta); diff --git a/src/script_opt/CPP/Exprs.cc b/src/script_opt/CPP/Exprs.cc index 0ac70abc14..c2a9cc2753 100644 --- a/src/script_opt/CPP/Exprs.cc +++ b/src/script_opt/CPP/Exprs.cc @@ -244,8 +244,8 @@ string CPPCompile::GenIncrExpr(const Expr* e, GenType gt, bool is_incr, bool top // twice, so easiest is to just transform this node // into the expanded equivalent. auto op = e->GetOp1(); - auto one = - e->GetType()->InternalType() == TYPE_INTERNAL_INT ? val_mgr->Int(1) : val_mgr->Count(1); + auto one = e->GetType()->InternalType() == TYPE_INTERNAL_INT ? val_mgr->Int(1) + : val_mgr->Count(1); auto one_e = make_intrusive(one); ExprPtr rhs; diff --git a/src/script_opt/CPP/Inits.cc b/src/script_opt/CPP/Inits.cc index d6f41da620..48f3dd1cc1 100644 --- a/src/script_opt/CPP/Inits.cc +++ b/src/script_opt/CPP/Inits.cc @@ -187,8 +187,8 @@ void CPPCompile::GenFuncVarInits() hashes += "}"; - auto init = - string("lookup_func__CPP(\"") + fn + "\", " + hashes + ", " + GenTypeName(ft) + ")"; + auto init = string("lookup_func__CPP(\"") + fn + "\", " + hashes + ", " + GenTypeName(ft) + + ")"; AddInit(fv, const_name, init); } @@ -226,8 +226,8 @@ void CPPCompile::GenPreInit(const Type* t) break; case TYPE_FILE: - pre_init = - string("make_intrusive(") + GenTypeName(t->AsFileType()->Yield()) + ")"; + pre_init = string("make_intrusive(") + GenTypeName(t->AsFileType()->Yield()) + + ")"; break; case TYPE_OPAQUE: diff --git a/src/script_opt/Expr.cc b/src/script_opt/Expr.cc index c87ef21b31..75e7fb74e7 100644 --- a/src/script_opt/Expr.cc +++ b/src/script_opt/Expr.cc @@ -402,8 +402,8 @@ ExprPtr Expr::AssignToTemporary(ExprPtr e, Reducer* c, StmtPtr& red_stmt) { auto result_tmp = c->GenTemporaryExpr(GetType(), e); - auto a_e = - make_intrusive(result_tmp->MakeLvalue(), e, false, nullptr, nullptr, false); + auto a_e = make_intrusive(result_tmp->MakeLvalue(), e, false, nullptr, nullptr, + false); a_e->SetIsTemp(); a_e->SetOriginal(ThisPtr()); diff --git a/src/script_opt/ZAM/Stmt.cc b/src/script_opt/ZAM/Stmt.cc index 01fbc3bcf7..84ca6598aa 100644 --- a/src/script_opt/ZAM/Stmt.cc +++ b/src/script_opt/ZAM/Stmt.cc @@ -837,8 +837,8 @@ const ZAMStmt ZAMCompiler::LoopOverTable(const ForStmt* f, const NameExpr* val) if ( value_var ) { - ZOp op = - no_loop_vars ? OP_NEXT_TABLE_ITER_VAL_VAR_NO_VARS_VVV : OP_NEXT_TABLE_ITER_VAL_VAR_VVV; + ZOp op = no_loop_vars ? OP_NEXT_TABLE_ITER_VAL_VAR_NO_VARS_VVV + : OP_NEXT_TABLE_ITER_VAL_VAR_VVV; z = ZInstI(op, FrameSlot(value_var), iter_slot, 0); z.CheckIfManaged(value_var->GetType()); z.op_type = OP_VVV_I2_I3; diff --git a/src/session/Manager.cc b/src/session/Manager.cc index 47f5b7d239..2fdb05c4e4 100644 --- a/src/session/Manager.cc +++ b/src/session/Manager.cc @@ -59,8 +59,8 @@ public: telemetry::IntCounterFamily total_family = telemetry_mgr->CounterFamily( "zeek", "total-sessions", {"protocol"}, "Total number of sessions", "1", true); - auto [it, inserted] = - entries.insert({protocol, Protocol{active_family, total_family, protocol}}); + auto [it, inserted] = entries.insert( + {protocol, Protocol{active_family, total_family, protocol}}); if ( inserted ) return it; diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index ab905f4ade..4b7d67e9a4 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -544,8 +544,8 @@ void zeek::detail::LineBufferedPipe::Emit(const char* msg) const } } - auto res = - hook->Invoke(make_intrusive(node_len, node), make_intrusive(msg)); + auto res = hook->Invoke(make_intrusive(node_len, node), + make_intrusive(msg)); do_print = res->AsBool(); } diff --git a/src/telemetry/Manager.cc b/src/telemetry/Manager.cc index 7a8da4a25d..d7eac6904e 100644 --- a/src/telemetry/Manager.cc +++ b/src/telemetry/Manager.cc @@ -81,8 +81,8 @@ IntHistogramFamily Manager::IntHistoFam(std::string_view prefix, std::string_vie [&, this](auto xs) { auto bounds = caf::span{ubounds.data(), ubounds.size()}; - auto ptr = - deref(pimpl).histogram_family(prefix, name, xs, bounds, helptext, unit, is_sum); + auto ptr = deref(pimpl).histogram_family(prefix, name, xs, bounds, helptext, unit, + is_sum); return IntHistogramFamily{opaque(ptr)}; }); } @@ -213,8 +213,8 @@ SCENARIO("telemetry managers provide access to counter families") } WHEN("retrieving a DblCounter family") { - auto family = - mgr.CounterFamily("zeek", "runtime", {"query"}, "test", "seconds", true); + auto family = mgr.CounterFamily("zeek", "runtime", {"query"}, "test", "seconds", + true); THEN("the family object stores the parameters") { CHECK_EQ(family.Prefix(), "zeek"sv); @@ -338,8 +338,8 @@ SCENARIO("telemetry managers provide access to gauge families") } WHEN("retrieving a DblGauge family") { - auto family = - mgr.GaugeFamily("zeek", "water-level", {"river"}, "test", "meters"); + auto family = mgr.GaugeFamily("zeek", "water-level", {"river"}, "test", + "meters"); THEN("the family object stores the parameters") { CHECK_EQ(family.Prefix(), "zeek"sv); @@ -461,8 +461,8 @@ SCENARIO("telemetry managers provide access to histogram families") WHEN("retrieving an IntHistogram family") { int64_t buckets[] = {10, 20}; - auto family = - mgr.HistogramFamily("zeek", "payload-size", {"protocol"}, buckets, "test", "bytes"); + auto family = mgr.HistogramFamily("zeek", "payload-size", {"protocol"}, buckets, "test", + "bytes"); THEN("the family object stores the parameters") { CHECK_EQ(family.Prefix(), "zeek"sv); diff --git a/src/util.cc b/src/util.cc index 14241481e6..cfa612a864 100644 --- a/src/util.cc +++ b/src/util.cc @@ -890,8 +890,8 @@ double calc_next_rotate(double current, double interval, double base) double startofday = mktime(&t); // current < startofday + base + i * interval <= current + interval - double delta_t = - startofday + base + ceil((current - startofday - base) / interval) * interval - current; + double delta_t = startofday + base + ceil((current - startofday - base) / interval) * interval - + current; return delta_t > 0.0 ? delta_t : interval; } diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index 07671948b1..dad543c282 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -371,8 +371,8 @@ static std::vector get_script_signature_files() std::vector rval; // Parse rule files defined on the script level. - char* script_signature_files = - util::copy_string(id::find_val("signature_files")->AsString()->CheckString()); + char* script_signature_files = util::copy_string( + id::find_val("signature_files")->AsString()->CheckString()); char* tmp = script_signature_files; char* s; @@ -921,8 +921,8 @@ SetupResult setup(int argc, char** argv, Options* zopts) packet_mgr->DumpDebug(); analyzer_mgr->DumpDebug(); - run_state::detail::have_pending_timers = - ! run_state::reading_traces && timer_mgr->Size() > 0; + run_state::detail::have_pending_timers = ! run_state::reading_traces && + timer_mgr->Size() > 0; return {0, std::move(options)}; } diff --git a/src/zeekygen/PackageInfo.cc b/src/zeekygen/PackageInfo.cc index bbdbb85c5d..f7ef9b1734 100644 --- a/src/zeekygen/PackageInfo.cc +++ b/src/zeekygen/PackageInfo.cc @@ -38,8 +38,8 @@ PackageInfo::PackageInfo(const string& arg_name) : Info(), pkg_name(arg_name), r string PackageInfo::DoReStructuredText(bool roles_only) const { - string rval = - util::fmt(":doc:`%s `\n\n", pkg_name.c_str(), pkg_name.c_str()); + string rval = util::fmt(":doc:`%s `\n\n", pkg_name.c_str(), + pkg_name.c_str()); for ( size_t i = 0; i < readme.size(); ++i ) rval += " " + readme[i] + "\n";