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

Applayer plugin 5053 v3.19 #12364

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

catenacyber
Copy link
Contributor

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

Describe changes:

  • app-layer plugins

#12363 without zabbix plugin in tree, and test fix due to splitting with #12307

Note that there is still #12307 to fix the limitation of probing parsers against 32 protocols (meaning any new app-layer like one in a plugin may be affected by this bug if it uses probing parsers for protocol detection)

Because some alprotos will remain static and defined as a constant,
such as ALPROTO_UNKNOWN=0, or ALPROTO_FAILED.

The regular already used protocols keep for now their static
identifier such as ALPROTO_SNMP, but this could be made more
dynamic in a later commit.

ALPROTO_FAILED was used in comparison and these needed to change to use
either ALPROTO_MAX or use standard function AppProtoIsValid
Ticket: 5053

The names are now dynamically registered at runtime.
The AppProto alproto enum identifiers are still static for now.

This is the final step before app-layer plugins.
Copy link

codecov bot commented Jan 9, 2025

Codecov Report

Attention: Patch coverage is 57.53425% with 93 lines in your changes missing coverage. Please review.

Project coverage is 80.50%. Comparing base (494d7bf) to head (404395b).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12364      +/-   ##
==========================================
- Coverage   82.54%   80.50%   -2.05%     
==========================================
  Files         912      913       +1     
  Lines      258028   258152     +124     
==========================================
- Hits       212988   207818    -5170     
- Misses      45040    50334    +5294     
Flag Coverage Δ
fuzzcorpus 56.38% <50.72%> (-4.34%) ⬇️
livemode 19.40% <45.89%> (+<0.01%) ⬆️
pcap 44.41% <51.20%> (-0.02%) ⬇️
suricata-verify 63.15% <53.88%> (-0.04%) ⬇️
unittests 58.56% <47.03%> (+0.44%) ⬆️

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

@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 24156

Copy link
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.

Getting close I think, some comments inline

@@ -24,53 +24,18 @@

#include "suricata-common.h"
#include "app-layer-protos.h"
#include "rust.h"

AppProto AlprotoMax = ALPROTO_MAX_STATIC;
Copy link
Member

Choose a reason for hiding this comment

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

style: should be snake case, probably g_alproto_max here. The g_ to indicate it is a global.

Alternatively it could be replaced by a inline func AlprotoMax() which would return a lower scoped static variable.

@@ -27,6 +27,11 @@

enum AppProtoEnum {
ALPROTO_UNKNOWN = 0,
/* used by the probing parser when alproto detection fails
* permanently for that particular stream */
ALPROTO_FAILED = 1,
Copy link
Member

Choose a reason for hiding this comment

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

should have a comment that any update to the value should also be updated in rust I think

/* keep last */
ALPROTO_MAX,
ALPROTO_MAX_STATIC,
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment that after this there will be dynamic id's?

@@ -1029,11 +1029,54 @@ void AppLayerListSupportedProtocols(void)
}

/***** Setup/General Registration *****/
static void AppLayerNamesSetup(void)
{
AppProtoRegisterProtoString(ALPROTO_UNKNOWN, "unknown");
Copy link
Member

Choose a reason for hiding this comment

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

can these move into the parser registrations? E.g.

  /**
   * \brief Register the SMTP Protocol parser.
   */
  void RegisterSMTPParsers(void)
  {
      const char *proto_name = "smtp";

     AppProtoRegisterProtoString(ALPROTO_SMTP, proto_name);

static size_t preregistered_callbacks_nb = 0;
static size_t preregistered_callbacks_cap = 0;

int SigTablePreRegister(void (*KeywordsRegister)(void))
Copy link
Member

Choose a reason for hiding this comment

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

we need some explanation of what this is here

@@ -708,6 +729,10 @@ void SigTableSetup(void)
ScDetectSipRegister();
ScDetectTemplateRegister();

for (size_t i = 0; i < preregistered_callbacks_nb; i++) {
preregistered_callbacks[i]();
Copy link
Member

Choose a reason for hiding this comment

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

style: function pointers using FunctionPointer style

static size_t preregistered_loggers_nb = 0;
static size_t preregistered_loggers_cap = 0;

int OutputPreRegisterLogger(EveJsonLoggerRegistrationData reg_data)
Copy link
Member

Choose a reason for hiding this comment

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

needs doc, like with detect

preregistered_loggers[i].confname, OutputJsonLogInitSub,
preregistered_loggers[i].alproto, JsonGenericDirFlowLogger, JsonLogThreadInit,
JsonLogThreadDeinit);
SCLogNotice(
Copy link
Member

Choose a reason for hiding this comment

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

don't think we want to keep this as notice

const char *logname;
AppProto alproto;
EveJsonSimpleTxLogFunc LogTx;
} EveJsonLoggerRegistrationData;
Copy link
Member

Choose a reason for hiding this comment

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

name is already long, but should it include an indication that it is about Tx logging and/or app-layer logging?

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