dns: cleanup: move DnsGetRcode (Lua) to rust

Move the implementation of Lua DnsGetRcode to Rust.
pull/4679/head
Jason Ish 6 years ago committed by Victor Julien
parent d6b3b33f4a
commit d809b0959b

@ -340,7 +340,7 @@ pub fn dns_rrtype_string(rrtype: u16) -> String {
}.to_string()
}
fn dns_rcode_string(flags: u16) -> String {
pub fn dns_rcode_string(flags: u16) -> String {
match flags & 0x000f {
DNS_RCODE_NOERROR => "NOERROR",
DNS_RCODE_FORMERR => "FORMERR",

@ -56,6 +56,24 @@ pub extern "C" fn rs_dns_lua_get_rrname(clua: &mut CLuaState,
return 0;
}
#[no_mangle]
pub extern "C" fn rs_dns_lua_get_rcode(clua: &mut CLuaState,
tx: &mut DNSTransaction)
-> c_int
{
let lua = LuaState{
lua: clua,
};
let rcode = tx.rcode();
if rcode > 0 {
lua.pushstring(&dns_rcode_string(rcode));
return 1;
}
return 0;
}
#[no_mangle]
pub extern "C" fn rs_dns_lua_get_query_table(clua: &mut CLuaState,
tx: &mut DNSTransaction)

@ -81,68 +81,3 @@ void DNSAppLayerRegisterGetEventInfoById(uint8_t ipproto, AppProto alproto)
return;
}
void DNSCreateRcodeString(uint8_t rcode, char *str, size_t str_size)
{
switch (rcode) {
case DNS_RCODE_NOERROR:
snprintf(str, str_size, "NOERROR");
break;
case DNS_RCODE_FORMERR:
snprintf(str, str_size, "FORMERR");
break;
case DNS_RCODE_SERVFAIL:
snprintf(str, str_size, "SERVFAIL");
break;
case DNS_RCODE_NXDOMAIN:
snprintf(str, str_size, "NXDOMAIN");
break;
case DNS_RCODE_NOTIMP:
snprintf(str, str_size, "NOTIMP");
break;
case DNS_RCODE_REFUSED:
snprintf(str, str_size, "REFUSED");
break;
case DNS_RCODE_YXDOMAIN:
snprintf(str, str_size, "YXDOMAIN");
break;
case DNS_RCODE_YXRRSET:
snprintf(str, str_size, "YXRRSET");
break;
case DNS_RCODE_NXRRSET:
snprintf(str, str_size, "NXRRSET");
break;
case DNS_RCODE_NOTAUTH:
snprintf(str, str_size, "NOTAUTH");
break;
case DNS_RCODE_NOTZONE:
snprintf(str, str_size, "NOTZONE");
break;
/* these are the same, need more logic */
case DNS_RCODE_BADVERS:
//case DNS_RCODE_BADSIG:
snprintf(str, str_size, "BADVERS/BADSIG");
break;
case DNS_RCODE_BADKEY:
snprintf(str, str_size, "BADKEY");
break;
case DNS_RCODE_BADTIME:
snprintf(str, str_size, "BADTIME");
break;
case DNS_RCODE_BADMODE:
snprintf(str, str_size, "BADMODE");
break;
case DNS_RCODE_BADNAME:
snprintf(str, str_size, "BADNAME");
break;
case DNS_RCODE_BADALG:
snprintf(str, str_size, "BADALG");
break;
case DNS_RCODE_BADTRUNC:
snprintf(str, str_size, "BADTRUNC");
break;
default:
SCLogDebug("could not map DNS rcode to name, bug!");
snprintf(str, str_size, "%04x/%u", rcode, rcode);
}
}

@ -88,28 +88,6 @@
#define DNS_RECORD_TYPE_ANY 255
#define DNS_RECORD_TYPE_URI 256
#define DNS_RCODE_NOERROR 0
#define DNS_RCODE_FORMERR 1
#define DNS_RCODE_SERVFAIL 2
#define DNS_RCODE_NXDOMAIN 3
#define DNS_RCODE_NOTIMP 4
#define DNS_RCODE_REFUSED 5
#define DNS_RCODE_YXDOMAIN 6
#define DNS_RCODE_YXRRSET 7
#define DNS_RCODE_NXRRSET 8
#define DNS_RCODE_NOTAUTH 9
#define DNS_RCODE_NOTZONE 10
// Support for OPT RR from RFC6891 will be needed to
// parse RCODE values over 15
#define DNS_RCODE_BADVERS 16
#define DNS_RCODE_BADSIG 16
#define DNS_RCODE_BADKEY 17
#define DNS_RCODE_BADTIME 18
#define DNS_RCODE_BADMODE 19
#define DNS_RCODE_BADNAME 20
#define DNS_RCODE_BADALG 21
#define DNS_RCODE_BADTRUNC 22
enum {
DNS_DECODER_EVENT_UNSOLLICITED_RESPONSE,
DNS_DECODER_EVENT_MALFORMED_DATA,
@ -139,6 +117,4 @@ int DNSStateGetEventInfoById(int event_id, const char **event_name,
void DNSAppLayerRegisterGetEventInfo(uint8_t ipproto, AppProto alproto);
void DNSAppLayerRegisterGetEventInfoById(uint8_t ipproto, AppProto alproto);
void DNSCreateRcodeString(uint8_t rcode, char *str, size_t str_size);
#endif /* __APP_LAYER_DNS_COMMON_H__ */

@ -86,20 +86,11 @@ static int DnsGetRcode(lua_State *luastate)
{
if (!(LuaStateNeedProto(luastate, ALPROTO_DNS)))
return LuaCallbackError(luastate, "error: protocol not dns");
uint16_t rcode = 0;
RSDNSTransaction *tx = LuaStateGetTX(luastate);
if (tx == NULL) {
return LuaCallbackError(luastate, "internal error: no tx");
}
uint16_t flags = rs_dns_tx_get_response_flags(tx);
rcode = flags & 0x000f;
if (rcode) {
char rcode_str[16] = "";
DNSCreateRcodeString(rcode, rcode_str, sizeof(rcode_str));
return LuaPushStringBuffer(luastate, (const uint8_t *)rcode_str, strlen(rcode_str));
} else {
return 0;
}
return rs_dns_lua_get_rcode(luastate, tx);
}
static int DnsGetRecursionDesired(lua_State *luastate)

Loading…
Cancel
Save