rust: export constants via cbindgen

so that constants are not defined twice in Rust anc C
So that we are sure they have the same value
pull/6680/head
Philippe Antoine 4 years ago committed by Victor Julien
parent 784558df2e
commit 87d9c44ec5

@ -104,6 +104,8 @@ exclude = [
"TFTPState",
"TFTPTransaction",
"free",
"IPPROTO_TCP",
"IPPROTO_UDP",
]
# Types of items that we'll generate. If empty, then all types of item are emitted.
@ -119,7 +121,7 @@ exclude = [
# * "functions":
#
# default: []
item_types = ["enums","structs","opaque","functions"]
item_types = ["enums","structs","opaque","functions","constants"]
# Whether applying rules in export.rename prevents export.prefix from applying.
#

@ -31,12 +31,14 @@ pub type AppLayerEventType = std::os::raw::c_int;
pub const APP_LAYER_EVENT_TYPE_TRANSACTION : i32 = 1;
pub const APP_LAYER_EVENT_TYPE_PACKET : i32 = 2;
// From stream.h.
pub const STREAM_START: u8 = 0x01;
pub const STREAM_EOF: u8 = 0x02;
pub const STREAM_TOSERVER: u8 = 0x04;
pub const STREAM_TOCLIENT: u8 = 0x08;
pub const STREAM_GAP: u8 = 0x10;
pub const STREAM_DEPTH: u8 = 0x20;
pub const STREAM_MIDSTREAM:u8 = 0x40;
pub const STREAM_FLUSH: u8 = 0x80;
pub const DIR_BOTH: u8 = 0b0000_1100;
const DIR_TOSERVER: u8 = 0b0000_0100;
const DIR_TOCLIENT: u8 = 0b0000_1000;

@ -125,9 +125,7 @@ fn mime_find_header_token<'a>(
}
}
// TODO ? export with "constants" in cbindgen
// and use in outbuf definition for rs_mime_find_header_token
// but other constants are now defined twice in rust and in C
// used on the C side
pub const RS_MIME_MAX_TOKEN_LEN: usize = 255;
#[no_mangle]

@ -25,6 +25,7 @@
#include "suricata-common.h"
#include "suricata.h"
#include "rust.h"
#include "decode.h"

@ -22,6 +22,7 @@
*/
#include "suricata-common.h"
#include "rust.h"
#include "stream-tcp-private.h"
#include "stream-tcp.h"
#include "stream-tcp-reassemble.h"

@ -26,15 +26,6 @@
#include "flow.h"
#define STREAM_START BIT_U8(0)
#define STREAM_EOF BIT_U8(1)
#define STREAM_TOSERVER BIT_U8(2)
#define STREAM_TOCLIENT BIT_U8(3)
#define STREAM_GAP BIT_U8(4) /**< data gap encountered */
#define STREAM_DEPTH BIT_U8(5) /**< depth reached */
#define STREAM_MIDSTREAM BIT_U8(6)
#define STREAM_FLUSH BIT_U8(7)
#define STREAM_FLAGS_FOR_PACKET(p) PKT_IS_TOSERVER((p)) ? STREAM_TOSERVER : STREAM_TOCLIENT
typedef int (*StreamSegmentCallback)(const Packet *, void *, const uint8_t *, uint32_t);

@ -530,9 +530,5 @@ extern int g_ut_covered;
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
#ifndef NAME_MAX
#define NAME_MAX 255
#endif
#endif /* __SURICATA_COMMON_H__ */

@ -1842,7 +1842,7 @@ static int ProcessMimeHeaders(const uint8_t *buf, uint32_t len,
uint8_t *rptr = NULL;
uint32_t blen = 0;
MimeDecEntity *entity = (MimeDecEntity *) state->stack->top->data;
uint8_t bptr[NAME_MAX];
uint8_t bptr[RS_MIME_MAX_TOKEN_LEN];
/* Look for mime header in current line */
ret = FindMimeHeader(buf, len, state);
@ -1871,14 +1871,13 @@ static int ProcessMimeHeaders(const uint8_t *buf, uint32_t len,
field = MimeDecFindField(entity, CTNT_DISP_STR);
if (field != NULL) {
bool truncated_name = false;
// NAME_MAX is RS_MIME_MAX_TOKEN_LEN on the rust side
if (rs_mime_find_header_token(field->value, field->value_len,
(const uint8_t *)"filename", strlen("filename"), &bptr, &blen)) {
SCLogDebug("File attachment found in disposition");
entity->ctnt_flags |= CTNT_IS_ATTACHMENT;
if (blen > NAME_MAX) {
blen = NAME_MAX;
if (blen > RS_MIME_MAX_TOKEN_LEN) {
blen = RS_MIME_MAX_TOKEN_LEN;
truncated_name = true;
}
@ -1902,7 +1901,7 @@ static int ProcessMimeHeaders(const uint8_t *buf, uint32_t len,
field = MimeDecFindField(entity, CTNT_TYPE_STR);
if (field != NULL) {
/* Check if child entity boundary definition found */
// NAME_MAX is RS_MIME_MAX_TOKEN_LEN on the rust side
// RS_MIME_MAX_TOKEN_LEN is RS_MIME_MAX_TOKEN_LEN on the rust side
if (rs_mime_find_header_token(field->value, field->value_len,
(const uint8_t *)"boundary", strlen("boundary"), &bptr, &blen)) {
state->found_child = 1;
@ -1926,14 +1925,13 @@ static int ProcessMimeHeaders(const uint8_t *buf, uint32_t len,
/* Look for file name (if not already found) */
if (!(entity->ctnt_flags & CTNT_IS_ATTACHMENT)) {
bool truncated_name = false;
// NAME_MAX is RS_MIME_MAX_TOKEN_LEN on the rust side
if (rs_mime_find_header_token(field->value, field->value_len,
(const uint8_t *)"name", strlen("name"), &bptr, &blen)) {
SCLogDebug("File attachment found");
entity->ctnt_flags |= CTNT_IS_ATTACHMENT;
if (blen > NAME_MAX) {
blen = NAME_MAX;
if (blen > RS_MIME_MAX_TOKEN_LEN) {
blen = RS_MIME_MAX_TOKEN_LEN;
truncated_name = true;
}
@ -3014,7 +3012,7 @@ static int MimeDecParseLongFilename01(void)
FAIL_IF_NOT(msg);
FAIL_IF_NOT(msg->anomaly_flags & ANOM_LONG_FILENAME);
FAIL_IF_NOT(msg->filename_len == NAME_MAX);
FAIL_IF_NOT(msg->filename_len == RS_MIME_MAX_TOKEN_LEN);
MimeDecFreeEntity(msg);

@ -41,6 +41,8 @@
#include "util-log-redis.h"
#endif /* HAVE_LIBHIREDIS */
#define LOGFILE_NAME_MAX 255
static bool LogFileNewThreadedCtx(LogFileCtx *parent_ctx, const char *log_path, const char *append, int i);
// Threaded eve.json identifier
@ -765,7 +767,7 @@ static bool LogFileNewThreadedCtx(LogFileCtx *parent_ctx, const char *log_path,
*thread = *parent_ctx;
if (parent_ctx->type == LOGFILE_TYPE_FILE) {
char fname[NAME_MAX];
char fname[LOGFILE_NAME_MAX];
if (!LogFileThreadedName(log_path, fname, sizeof(fname), SC_ATOMIC_ADD(eve_file_id, 1))) {
SCLogError(SC_ERR_MEM_ALLOC, "Unable to create threaded filename for log");
goto error;

Loading…
Cancel
Save