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

Dynamic alprotos : make SNMP totally dynamic #12402

Closed

Conversation

catenacyber
Copy link
Contributor

@catenacyber catenacyber commented Jan 16, 2025

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

Describe changes:

  • snmp: register protocol dynamically, to do so :
    • make some arrays even more dynamic
    • add an helper function AppProtoNewProtoFromString
    • have plugins be able to log flow or packet direction
  • rust : remove unneeded mut tx in loggers
  • detect: fix overflow for files protocol as reported by coverity

Follow up on #12383

CID 1640392

Would happen only if we reached 15 protocols handling files
Ticket: 5053

Do not asume that we know the number of alprotos at the end
of AppLayerNamesSetup, but make arrays allocated by later
AppLayerProtoDetectSetup dynamic so that it can be reallocated
from AppLayerParserRegisterProtocolParsers

This helps have a single entry point for a protocol like SNMP
So that we do not have to know g_alproto_max to register
dynamically a new protocol from its name
and cast

and also remove unneeded mut
Loggers do not change transactions, they read only.
@catenacyber
Copy link
Contributor Author

Already quite a few things going on here, so stopping here before adding the example of a template plugin

Let me know if this should be split into multiple PRs

@@ -37,7 +37,7 @@ fn tftp_log_request(tx: &mut TFTPTransaction,
}

#[no_mangle]
pub extern "C" fn rs_tftp_log_json_request(tx: &mut TFTPTransaction,
pub extern "C" fn rs_tftp_log_json_request(tx: &TFTPTransaction,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jasonish thoughts about this ?

Copy link
Member

Choose a reason for hiding this comment

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

Looks OK.

@@ -1683,7 +1696,6 @@ static void ValidateParserProto(AppProto alproto, uint8_t ipproto)
}
#undef BOTH_SET
#undef BOTH_SET_OR_BOTH_UNSET
#undef THREE_SET_OR_THREE_UNSET
Copy link
Contributor Author

Choose a reason for hiding this comment

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

was never defined :-p


// Also defined in output.h
// canot use JsonBuilder as it is not #[repr(C)]
pub type EveJsonSimpleTxLogFunc = unsafe extern "C" fn(*const c_void, *mut c_void) -> bool;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should cbindgen export types that are function prototypes ?

@@ -63,6 +63,7 @@ typedef struct SCAppLayerPlugin_ {
void (*KeywordsRegister)(void);
char *logname;
char *confname;
uint8_t dir;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wondering if we should we EveJsonTxLoggerRegistrationData

@@ -472,12 +472,49 @@ pub type ApplyTxConfigFn = unsafe extern "C" fn (*mut c_void, *mut c_void, c_int
pub type GetFrameIdByName = unsafe extern "C" fn(*const c_char) -> c_int;
pub type GetFrameNameById = unsafe extern "C" fn(u8) -> *const c_char;

// Also defined in output-json.h
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jasonish what do you think about this ?

I do not like to see this defined twice

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 get the C to use this? In some cases there will be no way around it, at least not without bindgen to output C types, and cbindgen to output Rust types. But currently some things just can't include "rust.h" to get the types as rust.h might have a dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you get the C to use this?

I did not manage

But currently some things just can't include "rust.h" to get the types as rust.h might have a dependency.

Indeed the problem

I will try again a bit more

// Also defined in output.h
#[repr(C)]
#[allow(non_snake_case)]
pub struct EveJsonTxLoggerRegistrationData {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not like to see it defined twice neither

@suricata-qa
Copy link

ERROR:

ERROR: QA failed on TREX_GENERIC_suri_cfg.

Pipeline 24229

@catenacyber
Copy link
Contributor Author

Next in #12406

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