Remove app-layer-dns-common.c as its no longer needed.
#[repr(u32)]
pub enum DNSEvent {
- MalformedData,
- NotRequest,
- NotResponse,
- ZFlagSet,
+ MalformedData = 0,
+ NotRequest = 1,
+ NotResponse = 2,
+ ZFlagSet = 3,
+}
+
+impl DNSEvent {
+ pub fn to_cstring(&self) -> &str {
+ match *self {
+ DNSEvent::MalformedData => "MALFORMED_DATA\0",
+ DNSEvent::NotRequest => "NOT_A_REQUEST\0",
+ DNSEvent::NotResponse => "NOT_A_RESPONSE\0",
+ DNSEvent::ZFlagSet => "Z_FLAG_SET\0",
+ }
+ }
+
+ pub fn from_id(id: u32) -> Option<DNSEvent> {
+ match id {
+ 0 => Some(DNSEvent::MalformedData),
+ 1 => Some(DNSEvent::NotRequest),
+ 2 => Some(DNSEvent::NotResponse),
+ 4 => Some(DNSEvent::ZFlagSet),
+ _ => None,
+ }
+ }
+
+ pub fn from_string(s: &str) -> Option<DNSEvent> {
+ match s.to_lowercase().as_ref() {
+ "malformed_data" => Some(DNSEvent::MalformedData),
+ "not_a_request" => Some(DNSEvent::NotRequest),
+ "not_a_response" => Some(DNSEvent::NotRequest),
+ "z_flag_set" => Some(DNSEvent::ZFlagSet),
+ _ => None
+ }
+ }
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn rs_dns_state_get_event_info_by_id(
+ event_id: std::os::raw::c_int,
+ event_name: *mut *const std::os::raw::c_char,
+ event_type: *mut core::AppLayerEventType,
+) -> std::os::raw::c_int {
+ if let Some(e) = DNSEvent::from_id(event_id as u32) {
+ *event_name = e.to_cstring().as_ptr() as *const std::os::raw::c_char;
+ *event_type = core::APP_LAYER_EVENT_TYPE_TRANSACTION;
+ return 0;
+ }
+ return -1;
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn rs_dns_state_get_event_info(
+ event_name: *const std::os::raw::c_char,
+ event_id: *mut std::os::raw::c_int,
+ event_type: *mut core::AppLayerEventType
+) -> std::os::raw::c_int {
+ if event_name == std::ptr::null() {
+ return -1;
+ }
+
+ let event_name = std::ffi::CStr::from_ptr(event_name);
+ if let Ok(event_name) = event_name.to_str() {
+ if let Some(event) = DNSEvent::from_string(event_name) {
+ *event_id = event as std::os::raw::c_int;
+ *event_type = core::APP_LAYER_EVENT_TYPE_TRANSACTION;
+ } else {
+ // Unknown event...
+ return -1;
+ }
+ } else {
+ // UTF-8 conversion failed. Should not happen.
+ return -1;
+ }
+
+ return 0;
}
#[derive(Debug,PartialEq)]
app-layer-detect-proto.c app-layer-detect-proto.h \
app-layer-dnp3.c app-layer-dnp3.h \
app-layer-dnp3-objects.c app-layer-dnp3-objects.h \
-app-layer-dns-common.c app-layer-dns-common.h \
+app-layer-dns-common.h \
app-layer-dns-tcp.c app-layer-dns-tcp.h \
app-layer-dns-udp.c app-layer-dns-udp.h \
app-layer-enip.c app-layer-enip.h \
+++ /dev/null
-/* Copyright (C) 2013-2014 Open Information Security Foundation
- *
- * You can copy, redistribute or modify this Program under the terms of
- * the GNU General Public License version 2 as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-
-/**
- * \file
- *
- * \author Victor Julien <victor@inliniac.net>
- */
-
-#include "suricata-common.h"
-#include "app-layer-dns-common.h"
-
-SCEnumCharMap dns_decoder_event_table[ ] = {
- { "MALFORMED_DATA", DNS_DECODER_EVENT_MALFORMED_DATA, },
- { "NOT_A_REQUEST", DNS_DECODER_EVENT_NOT_A_REQUEST, },
- { "NOT_A_RESPONSE", DNS_DECODER_EVENT_NOT_A_RESPONSE, },
- { "Z_FLAG_SET", DNS_DECODER_EVENT_Z_FLAG_SET, },
-
- { NULL, -1 },
-};
-
-int DNSStateGetEventInfo(const char *event_name,
- int *event_id, AppLayerEventType *event_type)
-{
- *event_id = SCMapEnumNameToValue(event_name, dns_decoder_event_table);
- if (*event_id == -1) {
- SCLogError(SC_ERR_INVALID_ENUM_MAP, "event \"%s\" not present in "
- "dns's enum map table.", event_name);
- /* this should be treated as fatal */
- return -1;
- }
-
- *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
-
- return 0;
-}
-
-int DNSStateGetEventInfoById(int event_id, const char **event_name,
- AppLayerEventType *event_type)
-{
- *event_name = SCMapEnumValueToName(event_id, dns_decoder_event_table);
- if (*event_name == NULL) {
- SCLogError(SC_ERR_INVALID_ENUM_MAP, "event \"%d\" not present in "
- "dns's enum map table.", event_id);
- /* this should be treated as fatal */
- return -1;
- }
-
- *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
-
- return 0;
-}
-
-void DNSAppLayerRegisterGetEventInfo(uint8_t ipproto, AppProto alproto)
-{
- AppLayerParserRegisterGetEventInfo(ipproto, alproto, DNSStateGetEventInfo);
-
- return;
-}
-
-void DNSAppLayerRegisterGetEventInfoById(uint8_t ipproto, AppProto alproto)
-{
- AppLayerParserRegisterGetEventInfoById(ipproto, alproto, DNSStateGetEventInfoById);
-
- return;
-}
#include "app-layer-protos.h"
#include "app-layer-parser.h"
-enum {
- DNS_DECODER_EVENT_MALFORMED_DATA,
- DNS_DECODER_EVENT_NOT_A_REQUEST,
- DNS_DECODER_EVENT_NOT_A_RESPONSE,
- DNS_DECODER_EVENT_Z_FLAG_SET,
-};
-
/** Opaque Rust types. */
/** \brief DNS packet header */
uint16_t additional_rr;
} __attribute__((__packed__)) DNSHeader;
-int DNSStateGetEventInfo(const char *event_name,
- int *event_id, AppLayerEventType *event_type);
-int DNSStateGetEventInfoById(int event_id, const char **event_name,
- AppLayerEventType *event_type);
void DNSAppLayerRegisterGetEventInfo(uint8_t ipproto, AppProto alproto);
void DNSAppLayerRegisterGetEventInfoById(uint8_t ipproto, AppProto alproto);
RustDNSGetAlstateProgress);
AppLayerParserRegisterGetStateProgressCompletionStatus(ALPROTO_DNS,
rs_dns_state_progress_completion_status);
- DNSAppLayerRegisterGetEventInfo(IPPROTO_TCP, ALPROTO_DNS);
- DNSAppLayerRegisterGetEventInfoById(IPPROTO_TCP, ALPROTO_DNS);
+ AppLayerParserRegisterGetEventInfo(IPPROTO_TCP, ALPROTO_DNS,
+ rs_dns_state_get_event_info);
+ AppLayerParserRegisterGetEventInfoById(IPPROTO_TCP, ALPROTO_DNS,
+ rs_dns_state_get_event_info_by_id);
/* This parser accepts gaps. */
AppLayerParserRegisterOptionFlags(IPPROTO_TCP, ALPROTO_DNS,
AppLayerParserRegisterGetStateProgressCompletionStatus(ALPROTO_DNS,
rs_dns_state_progress_completion_status);
- DNSAppLayerRegisterGetEventInfo(IPPROTO_UDP, ALPROTO_DNS);
- DNSAppLayerRegisterGetEventInfoById(IPPROTO_UDP, ALPROTO_DNS);
-
+ AppLayerParserRegisterGetEventInfo(IPPROTO_UDP, ALPROTO_DNS,
+ rs_dns_state_get_event_info);
+ AppLayerParserRegisterGetEventInfoById(IPPROTO_UDP, ALPROTO_DNS,
+ rs_dns_state_get_event_info_by_id);
} else {
SCLogConfig("Parsed disabled for %s protocol. Protocol detection"
"still on.", proto_name);