Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reorg: modular file reorganization of C source code - v9 #9973

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
854b39a
rustfmt: replace deprecated fn_args_layout with fn_params_layout
jasonish Nov 16, 2023
9b62280
rust: formatting does not force explicit abi
catenacyber Nov 30, 2023
24583e3
.gitignore: ignore src/**/.dirstamp
jasonish Dec 1, 2023
914c4f4
.gitignore: don't ignore config.h
jasonish Dec 5, 2023
6049ca8
reorg: disable clang-format around byte arrays
jasonish Dec 5, 2023
9ea81f6
reorg: clang-format src/*
jasonish Dec 5, 2023
7b9c194
reorg: clang-format branch
jasonish Dec 5, 2023
86fa93e
dnp3: move to app-layer
jasonish Dec 5, 2023
9d02d67
tftp: move to app-layer
jasonish Dec 5, 2023
dff8655
ftp: move to app-layer
jasonish Dec 5, 2023
50cf7c3
htp: move to app-layer
jasonish Dec 5, 2023
bbb358f
http2: move to app-layer
jasonish Dec 5, 2023
336f5b0
ike: move to app-layer
jasonish Dec 5, 2023
73df40f
krb5: move to app-layer
jasonish Dec 5, 2023
0a94a33
modbus: move to app-layer
jasonish Dec 5, 2023
ef2885e
mqtt: move to app-layer
jasonish Dec 5, 2023
009b59d
nfs: move to app-layer
jasonish Dec 5, 2023
1548fb6
ntp: move to app-layer
jasonish Dec 5, 2023
516ca4e
quic: move to app-layer
jasonish Dec 5, 2023
5ee1ff6
rdp: move to app-layer
jasonish Dec 5, 2023
0c8c4d3
rfb: move to app-layer
jasonish Dec 5, 2023
894e999
sip: move to app-layer
jasonish Dec 5, 2023
64fcb26
smb: move to app-layer
jasonish Dec 5, 2023
e50506d
smtp: move to app-layer
jasonish Dec 5, 2023
58891f8
snmp: move to app-layer
jasonish Dec 5, 2023
dc3a52b
ssl: move to app-layer
jasonish Dec 5, 2023
c5e348a
ssh: move to app-layer
jasonish Dec 5, 2023
dcf5ac6
enip: move to app-layer
jasonish Dec 5, 2023
cbf8f0a
http: move to app-layer
jasonish Dec 5, 2023
c66cc6b
pgsql: move to app-layer
jasonish Dec 5, 2023
ec76393
dns: move to app-layer
jasonish Dec 5, 2023
c4726a5
bittorrent-dht: move to app-layer
jasonish Dec 5, 2023
669f315
tls: move to app-layer
jasonish Dec 5, 2023
c67b29c
dcerpc: move to app-layer
jasonish Dec 5, 2023
766f9b8
template: move to app-layer
jasonish Dec 5, 2023
ab3dbab
dhcp: move to app-layer
jasonish Dec 5, 2023
a190b84
output: move output files to output/
jasonish Dec 5, 2023
33b6766
util: move util source into util/
jasonish Dec 5, 2023
34da074
windows: move win32 source into windows/
jasonish Dec 5, 2023
e213ce7
rust: rustfmt
jasonish Dec 5, 2023
4774335
src/Makefile.am: sort filenames
jasonish Dec 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ autom4te.cache/
build/*
compile
config.guess
config.h
config.log
config.status
config.sub
Expand Down Expand Up @@ -59,6 +58,7 @@ src/*.orig
src/*.plist/*
src/TAGS
src/suricata
src/**/*.dirstamp
stamp-h1
src/build-info.h
test.sh
Expand Down
2 changes: 1 addition & 1 deletion doc/userguide/capture-hardware/ebpf-xdp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ Confirm you have the XDP filter engaged in the output (example)::
(runmode-af-packet.c:424) <Info> (ParseAFPConfig) -- af-packet will use '/usr/libexec/suricata/ebpf/xdp_filter.bpf' as XDP filter file
(runmode-af-packet.c:429) <Config> (ParseAFPConfig) -- Using bypass kernel functionality for AF_PACKET (iface eth3)
(runmode-af-packet.c:609) <Config> (ParseAFPConfig) -- eth3: enabling zero copy mode by using data release call
(util-runmodes.c:296) <Info> (RunModeSetLiveCaptureWorkersForDevice) -- Going to use 8 thread(s)
(util/runmodes.c:296) <Info> (RunModeSetLiveCaptureWorkersForDevice) -- Going to use 8 thread(s)
...
...

Expand Down
4 changes: 2 additions & 2 deletions doc/userguide/devguide/codebase/code-style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,9 @@ File names

File names are all lowercase and have a .c. .h or .rs (Rust) extension.

Most files have a _subsystem_ prefix, e.g. ``detect-dsize.c, util-ip.c``
Most files have a _subsystem_ prefix, e.g. ``detect-dsize.c, util/ip.c``

Some cases have a multi-layer prefix, e.g. ``util-mpm-ac.c``
Some cases have a multi-layer prefix, e.g. ``util/mpm/mpm-ac.c``

Enums
~~~~~
Expand Down
2 changes: 1 addition & 1 deletion doc/userguide/devguide/codebase/unittests-c.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ From ``conf-yaml-loader.c``:
PASS;
}

In ``detect-ike-chosen-sa.c``, it is possible to see the freeing of resources (``DetectIkeChosenSaFree``) and the
In ``app-layer/ike/detect-chosen-sa.c``, it is possible to see the freeing of resources (``DetectIkeChosenSaFree``) and the
function that should group all the ``UtRegisterTest`` calls:

.. code-block:: c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,32 +159,32 @@ Implementing Frame support in C involves a bit more manual work, as one cannot m

Defining the frame types with the enum means:

.. literalinclude:: ../../../../../src/app-layer-htp.c
:caption: src/app-layer-htp.c
.. literalinclude:: ../../../../../src/app-layer/http/parser.c
:caption: src/app-layer/http/parser.c
:start-after: /* app-layer-frame-documentation tag start: HttpFrameTypes
:end-before: /* app-layer-frame-documentation tag end: HttpFrameTypes
:lines: 1-16

The HTTP parser uses the Frame registration functions from the C API (``app-layer-frames.c``) directly for registering request Frames. Here we also don't know the length yet. The ``0`` indicates flow direction: ``toserver``, and ``1`` would be used for ``toclient``:

.. literalinclude:: ../../../../../src/app-layer-htp.c
:caption: src/app-layer-htp.c
.. literalinclude:: ../../../../../src/app-layer/http/parser.c
:caption: src/app-layer/http/parser.c
:start-after: /* app-layer-frame-documentation tag start: frame registration http request
:end-before: /* app-layer-frame-documentation tag end: frame registration http request
:dedent: 4

Updating ``frame->len`` later:

.. literalinclude:: ../../../../../src/app-layer-htp.c
:caption: src/app-layer-htp.c
.. literalinclude:: ../../../../../src/app-layer/http/parser.c
:caption: src/app-layer/http/parser.c
:start-after: /* app-layer-frame-documentation tag start: updating frame->len
:end-before: /* app-layer-frame-documentation tag end: updating frame->len
:dedent: 4

Register relevant callbacks (note that the actual functions will also have to be written, for C):

.. literalinclude:: ../../../../../src/app-layer-htp.c
:caption: src/app-layer-htp.c
.. literalinclude:: ../../../../../src/app-layer/http/parser.c
:caption: src/app-layer/http/parser.c
:language: c
:start-after: /* app-layer-frame-documentation tag start: registering relevant callbacks
:end-before: /* app-layer-frame-documentation tag end: registering relevant callbacks
Expand Down
8 changes: 4 additions & 4 deletions doc/userguide/devguide/extending/app-layer/transactions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ likely happen once per transaction, by the time of its completion. In other case

In ``OutputTxLog``, the engine will compare current state with the value defined for the logging to happen, per flow
direction (``logger->tc_log_progress``, ``logger->ts_log_progress``). If state is less than that value, the engine skips to
the next logger. Code snippet from: suricata/src/output-tx.c:
the next logger. Code snippet from: suricata/src/output/output-tx.c:

.. code-block:: c

Expand Down Expand Up @@ -144,7 +144,7 @@ Code snippet from: rust/src/ssh/ssh.rs:
SshStateFinished = 3,
}

From src/app-layer-ftp.h:
From src/app-layer/ftp/parser.h:

.. code-block:: c

Expand All @@ -154,7 +154,7 @@ From src/app-layer-ftp.h:
FTP_STATE_FINISHED,
};

From src/app-layer-ssl.h:
From src/app-layer/ssl/parser.h:

.. code-block:: c

Expand Down Expand Up @@ -218,7 +218,7 @@ src/app-layer-dcerpc.c:

AppLayerParserRegisterStateProgressCompletionStatus(ALPROTO_DCERPC, 1, 1);

src/app-layer-ftp.c:
src/app-layer/ftp/parser.c:

.. code-block:: c

Expand Down
8 changes: 4 additions & 4 deletions doc/userguide/rules/file-keywords.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ info on the line it is ignored.

Output from md5sum is fine::

2f8d0355f0032c3e6311c6408d7c2dc2 util-path.c
b9cf5cf347a70e02fde975fc4e117760 util-pidfile.c
02aaa6c3f4dbae65f5889eeb8f2bbb8d util-pool.c
dd5fc1ee7f2f96b5f12d1a854007a818 util-print.c
2f8d0355f0032c3e6311c6408d7c2dc2 util/path.c
b9cf5cf347a70e02fde975fc4e117760 util/pidfile.c
02aaa6c3f4dbae65f5889eeb8f2bbb8d util/pool.c
dd5fc1ee7f2f96b5f12d1a854007a818 util/print.c

Just MD5's are good as well::

Expand Down
4 changes: 2 additions & 2 deletions examples/plugins/c-json-filetype/filetype.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#include "suricata-common.h"
#include "suricata-plugin.h"
#include "util-mem.h"
#include "util-debug.h"
#include "util/mem.h"
#include "util/debug.h"

#define FILETYPE_NAME "json-filetype-plugin"

Expand Down
4 changes: 3 additions & 1 deletion rust/derive/src/applayerevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ pub fn derive_app_layer_event(input: TokenStream) -> TokenStream {
// "crate", but if we're being used by a library or plugin user we need to reference the
// Suricata name space as "suricata". Check the CARGO_PKG_NAME environment variable to
// determine what identifier to setup.
let is_suricata = std::env::var("CARGO_PKG_NAME").map(|var| var == "suricata").unwrap_or(false);
let is_suricata = std::env::var("CARGO_PKG_NAME")
.map(|var| var == "suricata")
.unwrap_or(false);
let crate_id = if is_suricata {
syn::Ident::new("crate", proc_macro2::Span::call_site())
} else {
Expand Down
3 changes: 2 additions & 1 deletion rust/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Rust format configuration file. If empty, then this is a message that
# we expect the default formatting rules to be used.

fn_args_layout = "compressed"
fn_params_layout = "compressed"
force_explicit_abi = false
Loading
Loading