Skip to content

Applayer plugin 5053 v3.4#11795

Closed
catenacyber wants to merge 9 commits into
OISF:masterfrom
catenacyber:applayer-plugin-5053-v3.4
Closed

Applayer plugin 5053 v3.4#11795
catenacyber wants to merge 9 commits into
OISF:masterfrom
catenacyber:applayer-plugin-5053-v3.4

Conversation

@catenacyber
Copy link
Copy Markdown
Contributor

Link to ticket: https://redmine.openinfosecfoundation.org/issues/
Preliminary work for https://redmine.openinfosecfoundation.org/issues/5053

Describe changes:

  • get ready to use dynamic number of app-layer protos (also work with static constant) in some places
  • preventive fix of macro with parenthesis cc @jufajardini

#11572 next round

#11701 with comments taken into account

Still more work to do after :
Only AppProtoStrings is to be handled, but it is the big one.

And then take remaining commits out of #11321
And supply an example of an app-layer plugin

instead of a global variable.

For easier initialization with dynamic number of protocols
for expectation_proto

Ticket: 5053
so that we can use safely EXCEPTION_POLICY_MAX*sizeof(x)
Ticket: 5053

delay after initialization so that StringToAppProto works
@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 18, 2024

Codecov Report

Attention: Patch coverage is 90.52632% with 18 lines in your changes missing coverage. Please review.

Project coverage is 82.36%. Comparing base (d3eb656) to head (65f4fa8).
Report is 62 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11795      +/-   ##
==========================================
- Coverage   82.53%   82.36%   -0.18%     
==========================================
  Files         919      919              
  Lines      248979   248987       +8     
==========================================
- Hits       205506   205087     -419     
- Misses      43473    43900     +427     
Flag Coverage Δ
fuzzcorpus 59.50% <80.85%> (-0.83%) ⬇️
livemode 18.71% <69.14%> (+<0.01%) ⬆️
pcap 44.14% <84.04%> (-0.01%) ⬇️
suricata-verify 61.90% <90.42%> (+0.02%) ⬆️
unittests 58.99% <69.47%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@suricata-qa
Copy link
Copy Markdown

Information:

ERROR: QA failed on SURI_TLPR1_alerts_cmp.

field baseline test %
SURI_TLPR1_stats_chk
.app_layer.flow.dcerpc_tcp 40 42 105.0%

Pipeline 22740

@suricata-qa
Copy link
Copy Markdown

WARNING:

field baseline test %
SURI_TLPR1_stats_chk
.uptime 649 625 96.3%

Pipeline 22778

@catenacyber
Copy link
Copy Markdown
Contributor Author

I will do the commit autosquash after some review ;-)

@victorjulien
Copy link
Copy Markdown
Member

Commits are very light on explanation, please expand them a bit.

Copy link
Copy Markdown
Member

@victorjulien victorjulien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See inline comments / questions.

This PR still uses the hardcoded ALPROTO_MAX from the enum declaration, right? Is a next step to turn that into a variable?

Comment thread src/app-layer-detect-proto.c
const char **alproto_names;

/* Protocol expectations, like ftp-data on tcp */
uint8_t *expectation_proto;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the type here. What does it point to?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an array of ALPROTO_MAX "iptypes" : IPPROTO_TCP, IPPROTO_UDP or something else like 0
see AppLayerRegisterExpectationProto

{
SCEnter();

// should have just been realloced when dynamic protos is added
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is more a TODO note for me for the next PR that alpd_ctx.alproto_names should get reallocated when a new protocol registers itself

Comment thread src/app-layer-frames.c
Comment thread src/app-layer-parser.c

struct AppLayerParserThreadCtx_ {
void *alproto_local_storage[FLOW_PROTO_MAX][ALPROTO_MAX];
void *(*alproto_local_storage)[FLOW_PROTO_MAX];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this notation confuses me... what does it mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had a fixed-size 2-dimensional array of pointers (void *)

Now we have a fixed-size 1-dimensional array of pointers-as-pointer-to-an-array of pointers (void *)

This allows to keep notation alproto_local_storage[alproto][flow_proto] (as we know one dimension)

Alternative would be to use void **alproto_local_storage and index/access it like alproto_local_storage[alproto*FLOW_PROTO_MAX+flow_proto] (or have many allocations instead of just one contiguous SCCalloc(ALPROTO_MAX*FLOW_PROTO_MAX, sizeof(void *)))

Comment thread src/app-layer-parser.c
{
SCEnter();
memset(&alp_ctx, 0, sizeof(alp_ctx));
// to realloc when dynamic protos are added
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment confused me, do you mean something like "initial allocation that will later be grown using realloc" or something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Comment thread src/app-layer-parser.c
*/
static int AppLayerParserTest01(void)
{
AppLayerParserBackupParserTable();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we just not need this anymore?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, I am not sure what these AppLayerParserTest01 really test : they check that AppLayerParserParse returns failure for this newly registered ALPROTO_TEST as TestProtocolParser returns error but it would also return failure without the registration...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, could we remove this ALPROTO_TEST ?

@catenacyber
Copy link
Copy Markdown
Contributor Author

This PR still uses the hardcoded ALPROTO_MAX from the enum declaration, right? Is a next step to turn that into a variable?

Right, a bit like 61ae154

@catenacyber
Copy link
Copy Markdown
Contributor Author

Next in #11910

@catenacyber catenacyber closed this Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants