let state = cast_pointer!(state, DHCPState);
let buf = build_slice!(input, input_len as usize);
if state.parse(buf) {
- return 1;
+ return 0;
}
return -1;
}
let state = cast_pointer!(state, DNSState);
let buf = unsafe{std::slice::from_raw_parts(input, input_len as usize)};
if state.parse_request(buf) {
- 1
+ 0
} else {
-1
}
let state = cast_pointer!(state, DNSState);
let buf = unsafe{std::slice::from_raw_parts(input, input_len as usize)};
if state.parse_response(buf) {
- 1
+ 0
} else {
-1
}
_flags: u8) -> i32 {
let buf = build_slice!(input,input_len as usize);
let state = cast_pointer!(state,IKEV2State);
- state.parse(buf, STREAM_TOSERVER)
+ let res = state.parse(buf, STREAM_TOSERVER);
+ if res < 0 {
+ return res;
+ }
+ 0
}
#[no_mangle]
APP_LAYER_PARSER_BYPASS_READY)
};
}
- res
+ if res < 0 {
+ return res;
+ }
+ 0
}
#[no_mangle]
2 => {
self.process_request_record_v2(r)
},
- _ => { 1 },
+ _ => { 0 },
}
}
let consumed = self.filetracker_update(STREAM_TOSERVER, &gap, gap_size);
if consumed > gap_size {
SCLogDebug!("consumed more than GAP size: {} > {}", consumed, gap_size);
- return 1;
+ return 0;
}
self.ts_ssn_gap = true;
self.ts_gap = true;
let consumed = self.filetracker_update(STREAM_TOCLIENT, &gap, gap_size);
if consumed > gap_size {
SCLogDebug!("consumed more than GAP size: {} > {}", consumed, gap_size);
- return 1;
+ return 0;
}
self.tc_ssn_gap = true;
self.tc_gap = true;
// bad.
self.set_event(NFSEvent::MalformedData);
- status = 1;
+ status = 0;
},
Err(nom::Err::Error(_e)) |
Err(nom::Err::Failure(_e)) => {
// bad.
self.set_event(NFSEvent::MalformedData);
- status = 1;
+ status = 0;
},
Err(nom::Err::Error(_e)) |
Err(nom::Err::Failure(_e)) => {
2 => {
status |= self.process_request_record_v2(rpc_record);
},
- _ => { status = 1; },
+ _ => { status = 0; },
}
},
Err(nom::Err::Incomplete(_)) => {
Err(nom::Err::Failure(_e)) => { SCLogDebug!("Parsing failed: {:?}", _e); }
}
}
+ SCLogDebug!("status {}", status);
status
}
state.ts = flow.get_last_time().as_secs();
if state.parse_tcp_data_ts(buf) == 0 {
- 1
+ 0
} else {
-1
}
-> i8
{
if state.parse_tcp_data_ts_gap(input_len as u32) == 0 {
- return 1;
+ return 0;
}
return -1;
}
state.ts = flow.get_last_time().as_secs();
if state.parse_tcp_data_tc(buf) == 0 {
- 1
+ 0
} else {
-1
}
-> i8
{
if state.parse_tcp_data_tc_gap(input_len as u32) == 0 {
- return 1;
+ return 0;
}
return -1;
}
SCLogDebug!("parsing {} bytes of request data", input_len);
if state.parse_udp_ts(buf) == 0 {
- 1
+ 0
} else {
-1
}
let buf = unsafe{std::slice::from_raw_parts(input, input_len as usize)};
if state.parse_udp_tc(buf) == 0 {
- 1
+ 0
} else {
-1
}
tx.xid = msg.ref_id;
self.transactions.push(tx);
}
- 1
+ 0
},
Err(nom::Err::Incomplete(_)) => {
SCLogDebug!("Insufficient data while parsing NTP data");
];
let mut state = NTPState::new();
- assert_eq!(1, state.parse(REQ, 0));
+ assert_eq!(0, state.parse(REQ, 0));
}
}
let buf = build_slice!(input, input_len as usize);
// attempt to parse bytes as `rdp` protocol
if state.parse_ts(buf) {
- return 1;
+ return 0;
}
// no need for further parsing
return -1;
let buf = build_slice!(input, input_len as usize);
// attempt to parse bytes as `rdp` protocol
if state.parse_tc(buf) {
- return 1;
+ return 0;
}
// no need for further parsing
return -1;
let buf = build_slice!(input, input_len as usize);
let state = cast_pointer!(state, SIPState);
if state.parse_request(buf) {
- 1
+ 0
} else {
-1
}
let buf = build_slice!(input, input_len as usize);
let state = cast_pointer!(state, SIPState);
if state.parse_response(buf) {
- 1
+ 0
} else {
-1
}
state.ts = flow.get_last_time().as_secs();
if state.parse_tcp_data_ts(buf) == 0 {
- return 1;
+ return 0;
} else {
return -1;
}
-> i8
{
if state.parse_tcp_data_ts_gap(input_len as u32) == 0 {
- return 1;
+ return 0;
}
return -1;
}
state.ts = flow.get_last_time().as_secs();
if state.parse_tcp_data_tc(buf) == 0 {
- return 1;
+ return 0;
} else {
return -1;
}
-> i8
{
if state.parse_tcp_data_tc_gap(input_len as u32) == 0 {
- return 1;
+ return 0;
}
return -1;
}
state.tx_id += 1;
rqst.id = state.tx_id;
state.transactions.push(rqst);
- 1
+ 0
},
_ => 0
}
SCEnter();
if (input == NULL && AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF)) {
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
} else if (input == NULL || input_len == 0) {
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
DCERPCUDPState *sstate = (DCERPCUDPState *) dcerpc_state;
sstate->bytesprocessed = 0;
}
if (pstate == NULL)
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
}
static void *DCERPCUDPStateAlloc(void)
DCERPCState *sstate = (DCERPCState *) dcerpc_state;
if (input == NULL && AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF)) {
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
} else if (input == NULL || input_len == 0) {
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
if (sstate->dcerpc.bytesprocessed != 0 && sstate->data_needed_for_dir != dir) {
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
retval = DCERPCParser(&sstate->dcerpc, input, input_len);
if (retval == -1) {
- SCReturnInt(0);
+ SCReturnInt(APP_LAYER_OK);
}
sstate->data_needed_for_dir = dir;
if (pstate == NULL)
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
}
static int DCERPCParseRequest(Flow *f, void *dcerpc_state,
int processed = 0;
if (input_len == 0) {
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
}
if (buffer->len) {
}
}
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
error:
/* Reset the buffer. */
DNP3BufferReset(buffer);
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
/**
}
done:
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
error:
/* An error occurred while processing DNP3 frames. Dump the
* buffer as we can't be assured that they are valid anymore. */
DNP3BufferReset(buffer);
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
static AppLayerDecoderEvents *DNP3GetEvents(void *tx)
if (input == NULL && AppLayerParserStateIssetFlag(pstate,
APP_LAYER_PARSER_EOF))
{
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
} else if (input == NULL && input_len != 0) {
// GAP
- SCReturnInt(0);
+ SCReturnInt(APP_LAYER_OK);
} else if (input == NULL || input_len == 0)
{
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
while (input_len > 0)
{
tx = ENIPTransactionAlloc(enip);
if (tx == NULL)
- SCReturnInt(0);
+ SCReturnInt(APP_LAYER_OK);
SCLogDebug("ENIPParse input len %d", input_len);
DecodeENIPPDU(input, input_len, tx);
}
}
- return 1;
+ SCReturnInt(APP_LAYER_OK);
}
* \param input_len length of the request
* \param output the resulting output
*
- * \retval 1 when the command is parsed, 0 otherwise
+ * \retval APP_LAYER_OK when input was process successfully
+ * \retval APP_LAYER_ERROR when a unrecoverable error was encountered
*/
static int FTPParseRequest(Flow *f, void *ftp_state,
AppLayerParserState *pstate,
void *ptmp;
if (input == NULL && AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF)) {
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
} else if (input == NULL || input_len == 0) {
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
state->input = input;
FTPTransaction *tx = FTPTransactionCreate(state);
if (unlikely(tx == NULL))
- return -1;
+ SCReturnInt(APP_LAYER_ERROR);
state->curr_tx = tx;
tx->command_descriptor = cmd_descriptor;
state->port_line = NULL;
state->port_line_size = 0;
}
- return 0;
+ SCReturnInt(APP_LAYER_OK);
}
state->port_line = ptmp;
state->port_line_size = state->current_line_len;
*/
direction = STREAM_TOCLIENT;
// fallthrough
- case FTP_COMMAND_STOR:
- {
+ case FTP_COMMAND_STOR: {
/* Ensure that there is a negotiated dyn port and a file
* name -- need more than 5 chars: cmd [4], space, <filename>
*/
if (state->dyn_port == 0 || state->current_line_len < 6) {
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
struct FtpTransferCmd *data = FTPCalloc(1, sizeof(struct FtpTransferCmd));
if (data == NULL)
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
data->DFree = FtpTransferCmdFree;
/* Min size has been checked in FTPParseRequestCommand */
data->file_name = FTPCalloc(state->current_line_len - 4, sizeof(char));
if (data->file_name == NULL) {
FtpTransferCmdFree(data);
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
data->file_name[state->current_line_len - 5] = 0;
data->file_len = state->current_line_len - 5;
if (ret == -1) {
FtpTransferCmdFree(data);
SCLogDebug("No expectation created.");
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
} else {
SCLogDebug("Expectation created [direction: %s, dynamic port %"PRIu16"].",
state->active ? "to server" : "to client",
}
}
- return 1;
+ SCReturnInt(APP_LAYER_OK);
}
static int FTPParsePassiveResponse(Flow *f, FtpState *state, const uint8_t *input, uint32_t input_len)
/**
* \brief Handle preliminary replies -- keep tx open
- * \retval: True for a positive preliminary reply; false otherwise
+ * \retval bool True for a positive preliminary reply; false otherwise
*
* 1yz Positive Preliminary reply
*
void *local_data, const uint8_t flags)
{
FtpState *state = (FtpState *)ftp_state;
- int retcode = 1;
if (unlikely(input_len == 0)) {
- return 1;
+ SCReturnInt(APP_LAYER_OK);
}
FTPTransaction *tx = FTPGetOldestTx(state);
tx = FTPTransactionCreate(state);
}
if (unlikely(tx == NULL)) {
- return -1;
+ SCReturnInt(APP_LAYER_ERROR);
}
if (state->command == FTP_COMMAND_UNKNOWN || tx->command_descriptor == NULL) {
/* unknown */
if (state->command == FTP_COMMAND_EPRT) {
uint16_t dyn_port = rs_ftp_active_eprt(state->port_line, state->port_line_len);
if (dyn_port == 0) {
- retcode = 0;
goto tx_complete;
}
state->dyn_port = dyn_port;
if ((flags & STREAM_TOCLIENT)) {
uint16_t dyn_port = rs_ftp_active_port(state->port_line, state->port_line_len);
if (dyn_port == 0) {
- retcode = 0;
goto tx_complete;
}
state->dyn_port = dyn_port;
/* Handle preliminary replies -- keep tx open */
if (FTPIsPPR(input, input_len)) {
- return retcode;
+ SCReturnInt(APP_LAYER_OK);
}
tx_complete:
tx->done = true;
- return retcode;
+ SCReturnInt(APP_LAYER_OK);
}
void *local_data, const uint8_t flags)
{
SCEnter();
- int ret = 1;
+ int ret = 0;
HtpState *hstate = (HtpState *)htp_state;
/* On the first invocation, create the connection parser structure to
void *local_data, const uint8_t flags)
{
SCEnter();
- int ret = 1;
+ int ret = 0;
HtpState *hstate = (HtpState *)htp_state;
/* On the first invocation, create the connection parser structure to
ModbusHeader header;
if (input == NULL && AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF)) {
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
} else if (input == NULL || input_len == 0) {
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
while (input_len > 0) {
/* Extract MODBUS Header */
if (ModbusParseHeader(modbus, &header, adu, adu_len))
- SCReturnInt(0);
+ SCReturnInt(APP_LAYER_OK);
/* Update ADU length with length in Modbus header. */
adu_len = (uint32_t) sizeof(ModbusHeader) + (uint32_t) header.length - 1;
if (adu_len > input_len)
- SCReturnInt(0);
+ SCReturnInt(APP_LAYER_OK);
/* Allocate a Transaction Context and add it to Transaction list */
tx = ModbusTxAlloc(modbus);
if (tx == NULL)
- SCReturnInt(0);
+ SCReturnInt(APP_LAYER_OK);
/* Check MODBUS Header */
ModbusCheckHeader(modbus, &header);
input_len -= adu_len;
}
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
}
/** \internal
ModbusTransaction *tx;
if (input == NULL && AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF)) {
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
} else if (input == NULL || input_len == 0) {
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
while (input_len > 0) {
/* Extract MODBUS Header */
if (ModbusParseHeader(modbus, &header, adu, adu_len))
- SCReturnInt(0);
+ SCReturnInt(APP_LAYER_OK);
/* Update ADU length with length in Modbus header. */
adu_len = (uint32_t) sizeof(ModbusHeader) + (uint32_t) header.length - 1;
if (adu_len > input_len)
- SCReturnInt(0);
+ SCReturnInt(APP_LAYER_OK);
/* Find the transaction context thanks to transaction ID (and function code) */
tx = ModbusTxFindByTransaction(modbus, header.transactionId);
/* and add it to Transaction list */
tx = ModbusTxAlloc(modbus);
if (tx == NULL)
- SCReturnInt(0);
+ SCReturnInt(APP_LAYER_OK);
SCLogDebug("MODBUS_DECODER_EVENT_UNSOLICITED_RESPONSE");
ModbusSetEvent(modbus, MODBUS_DECODER_EVENT_UNSOLICITED_RESPONSE);
input_len -= adu_len;
}
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
}
/** \internal
/* invoke the recursive parser, but only on data. We may get empty msgs on EOF */
if (input_len > 0 || (flags & STREAM_EOF)) {
/* invoke the parser */
- if (p->Parser[(flags & STREAM_TOSERVER) ? 0 : 1](f, alstate, pstate,
+ int parse_res = p->Parser[(flags & STREAM_TOSERVER) ? 0 : 1](f, alstate, pstate,
input, input_len,
alp_tctx->alproto_local_storage[f->protomap][alproto],
- flags) < 0)
+ flags);
+ if (parse_res < 0)
{
goto error;
}
* completely inspected */
#define APP_LAYER_TX_PREFILTER_MASK ~APP_LAYER_TX_INSPECTED_FLAG
+#define APP_LAYER_OK 0
+#define APP_LAYER_ERROR -1
+
int AppLayerParserProtoIsRegistered(uint8_t ipproto, AppProto alproto);
/***** transaction handling *****/
res = rs_smb_parse_request_tcp(f, state, pstate, input, input_len,
local_data, flags);
}
- if (res != 1) {
+ if (res != 0) {
SCLogDebug("SMB request%s of %u bytes, retval %d",
(input == NULL && input_len > 0) ? " is GAP" : "", input_len, res);
}
res = rs_smb_parse_response_tcp(f, state, pstate, input, input_len,
local_data, flags);
}
- if (res != 1) {
+ if (res != 0) {
SCLogDebug("SMB response%s of %u bytes, retval %d",
(input == NULL && input_len > 0) ? " is GAP" : "", input_len, res);
}
SCEnter();
if (input == NULL && AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF)) {
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
} else if (input == NULL || input_len == 0) {
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
state->input = input;
if (direction == 0) {
while (SMTPGetLine(state) >= 0) {
if (SMTPProcessRequest(state, f, pstate) == -1)
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
/* toclient */
} else {
while (SMTPGetLine(state) >= 0) {
if (SMTPProcessReply(state, f, pstate, thread_data) == -1)
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
}
- SCReturnInt(0);
+ SCReturnInt(APP_LAYER_OK);
}
static int SMTPParseClientRecord(Flow *f, void *alstate,
SshHeader *ssh_header = &ssh_state->cli_hdr;
if (input == NULL && AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF)) {
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
} else if (input == NULL || input_len == 0) {
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
int r = SSHParseData(ssh_state, ssh_header, input, input_len);
AppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_BYPASS_READY);
}
- SCReturnInt(r);
+ if (r < 0) {
+ SCReturnInt(APP_LAYER_ERROR);
+ }
+ SCReturnInt(APP_LAYER_OK);
}
static int SSHParseResponse(Flow *f, void *state, AppLayerParserState *pstate,
SshHeader *ssh_header = &ssh_state->srv_hdr;
if (input == NULL && AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF)) {
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
} else if (input == NULL || input_len == 0) {
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
int r = SSHParseData(ssh_state, ssh_header, input, input_len);
AppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_BYPASS_READY);
}
- SCReturnInt(r);
+ if (r < 0) {
+ SCReturnInt(APP_LAYER_ERROR);
+ }
+ SCReturnInt(APP_LAYER_OK);
}
/** \brief Function to allocates the SSH state memory
AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF)) {
/* flag session as finished if APP_LAYER_PARSER_EOF is set */
ssl_state->flags |= SSL_AL_FLAG_STATE_FINISHED;
- SCReturnInt(1);
+ SCReturnInt(APP_LAYER_OK);
} else if (input == NULL || input_len == 0) {
- SCReturnInt(-1);
+ SCReturnInt(APP_LAYER_ERROR);
}
if (direction == 0)
SSLParserReset(ssl_state);
SSLSetEvent(ssl_state,
TLS_DECODER_EVENT_TOO_MANY_RECORDS_IN_PACKET);
- return -1;
+ return APP_LAYER_ERROR;
}
/* ssl_state->bytes_processed is zero for a fresh record or
SSLParserReset(ssl_state);
SSLSetEvent(ssl_state,
TLS_DECODER_EVENT_INVALID_SSL_RECORD);
- return -1;
+ return APP_LAYER_ERROR;
} else {
input_len -= retval;
input += retval;
SSLParserReset(ssl_state);
SSLSetEvent(ssl_state,
TLS_DECODER_EVENT_INVALID_SSL_RECORD);
- return -1;
+ return APP_LAYER_ERROR;
} else {
input_len -= retval;
input += retval;
SCLogDebug("Error parsing SSLv2.x. Reseting parser "
"state. Let's get outta here");
SSLParserReset(ssl_state);
- return 0;
+ return APP_LAYER_OK;
} else {
input_len -= retval;
input += retval;
SCLogDebug("Error parsing SSLv3.x. Reseting parser "
"state. Let's get outta here");
SSLParserReset(ssl_state);
- return 0;
+ return APP_LAYER_OK;
} else {
if (retval > input_len) {
SCLogDebug("Error parsing SSLv3.x. Reseting parser "
if (AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF))
ssl_state->flags |= SSL_AL_FLAG_STATE_FINISHED;
- return 1;
+ return APP_LAYER_OK;
}
static int SSLParseClientRecord(Flow *f, void *alstate, AppLayerParserState *pstate,