#[repr(u32)]
pub enum DNSEvent {
- MalformedData = 0,
- NotRequest = 1,
- NotResponse = 2,
- ZFlagSet = 3,
+ MalformedData,
+ NotRequest,
+ NotResponse,
+ ZFlagSet,
+ InvalidOpcode,
}
impl DNSEvent {
DNSEvent::NotRequest => "NOT_A_REQUEST\0",
DNSEvent::NotResponse => "NOT_A_RESPONSE\0",
DNSEvent::ZFlagSet => "Z_FLAG_SET\0",
+ DNSEvent::InvalidOpcode => "INVALID_OPCODE\0",
}
}
1 => Some(DNSEvent::NotRequest),
2 => Some(DNSEvent::NotResponse),
4 => Some(DNSEvent::ZFlagSet),
+ 5 => Some(DNSEvent::InvalidOpcode),
_ => None,
}
}
"not_a_request" => Some(DNSEvent::NotRequest),
"not_a_response" => Some(DNSEvent::NotRequest),
"z_flag_set" => Some(DNSEvent::ZFlagSet),
+ "invalid_opcode" => Some(DNSEvent::InvalidOpcode),
_ => None
}
}
}
let z_flag = request.header.flags & 0x0040 != 0;
+ let opcode = ((request.header.flags >> 11) & 0xf) as u8;
let mut tx = self.new_tx();
tx.request = Some(request);
self.set_event(DNSEvent::ZFlagSet);
}
+ if opcode >= 7 {
+ self.set_event(DNSEvent::InvalidOpcode);
+ }
+
return true;
}
Err(nom::Err::Incomplete(_)) => {
}
let z_flag = response.header.flags & 0x0040 != 0;
+ let opcode = ((response.header.flags >> 11) & 0xf) as u8;
let mut tx = self.new_tx();
if let Some(ref mut config) = &mut self.config {
self.set_event(DNSEvent::ZFlagSet);
}
+ if opcode >= 7 {
+ self.set_event(DNSEvent::InvalidOpcode);
+ }
+
return true;
}
Err(nom::Err::Incomplete(_)) => {
const DNS_HEADER_SIZE: usize = 12;
fn probe_header_validity(header: DNSHeader, rlen: usize) -> (bool, bool, bool) {
- let opcode = ((header.flags >> 11) & 0xf) as u8;
- if opcode >= 7 {
- //unassigned opcode
- return (false, false, false);
- }
if 2 * (header.additional_rr as usize
+ header.answer_rr as usize
+ header.authority_rr as usize
js.set_bool("z", true)?;
}
- for query in &response.queries {
+ let opcode = ((header.flags >> 11) & 0xf) as u8;
+ js.set_uint("opcode", opcode as u64)?;
+
+ if let Some(query) = response.queries.first() {
js.set_string_from_bytes("rrname", &query.name)?;
js.set_string("rrtype", &dns_rrtype_string(query.rrtype))?;
- break;
}
js.set_string("rcode", &dns_rcode_string(header.flags))?;
if request.header.flags & 0x0040 != 0 {
jb.set_bool("z", true)?;
}
+ let opcode = ((request.header.flags >> 11) & 0xf) as u8;
+ jb.set_uint("opcode", opcode as u64)?;
return Ok(true);
}
}