mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-12 14:10:36 -04:00
Prepare DNS decoding
This commit is contained in:
parent
5eeed9b206
commit
3eef5e0699
49
kernel/include/net/dns_layer.hpp
Normal file
49
kernel/include/net/dns_layer.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
//=======================================================================
|
||||
// Copyright Baptiste Wicht 2013-2016.
|
||||
// Distributed under the terms of the MIT License.
|
||||
// (See accompanying file LICENSE or copy at
|
||||
// http://www.opensource.org/licenses/MIT)
|
||||
//=======================================================================
|
||||
|
||||
#ifndef NET_DNS_LAYER_H
|
||||
#define NET_DNS_LAYER_H
|
||||
|
||||
#include <types.hpp>
|
||||
|
||||
#include "net/ethernet_layer.hpp"
|
||||
#include "net/ip_layer.hpp"
|
||||
#include "net/network.hpp"
|
||||
|
||||
namespace network {
|
||||
|
||||
namespace dns {
|
||||
|
||||
struct flags_t {
|
||||
uint8_t qr : 1;
|
||||
uint8_t opcode : 4;
|
||||
uint8_t aa : 1;
|
||||
uint8_t tc : 1;
|
||||
uint8_t rd : 1;
|
||||
uint8_t ra : 1;
|
||||
uint8_t zeroes : 3;
|
||||
uint8_t rcode : 4;
|
||||
} __attribute__((packed));
|
||||
|
||||
static_assert(sizeof(flags_t) == 2, "DNS flags must be 16 bits");
|
||||
|
||||
struct header {
|
||||
uint16_t identification;
|
||||
flags_t flags;
|
||||
uint16_t questions;
|
||||
uint16_t answers;
|
||||
uint16_t authority_rrs;
|
||||
uint16_t additional_rrs;
|
||||
} __attribute__((packed));
|
||||
|
||||
void decode(network::interface_descriptor& interface, network::ethernet::packet& packet);
|
||||
|
||||
} // end of dns namespace
|
||||
|
||||
} // end of network namespace
|
||||
|
||||
#endif
|
41
kernel/src/net/dns_layer.cpp
Normal file
41
kernel/src/net/dns_layer.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
//=======================================================================
|
||||
// Copyright Baptiste Wicht 2013-2016.
|
||||
// Distributed under the terms of the MIT License.
|
||||
// (See accompanying file LICENSE or copy at
|
||||
// http://www.opensource.org/licenses/MIT)
|
||||
//=======================================================================
|
||||
|
||||
#include "net/dns_layer.hpp"
|
||||
|
||||
#include "kernel_utils.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
} //end of anonymous namespace
|
||||
|
||||
void network::dns::decode(network::interface_descriptor& /*interface*/, network::ethernet::packet& packet){
|
||||
packet.tag(3, packet.index);
|
||||
|
||||
auto* dns_header = reinterpret_cast<header*>(packet.payload + packet.index);
|
||||
|
||||
logging::logf(logging::log_level::TRACE, "dns: Start DNS packet handling\n");
|
||||
|
||||
auto identification = switch_endian_16(dns_header->identification);
|
||||
auto questions = switch_endian_16(dns_header->questions);
|
||||
auto answers = switch_endian_16(dns_header->answers);
|
||||
|
||||
logging::logf(logging::log_level::TRACE, "dns: Identification %h \n", size_t(identification));
|
||||
logging::logf(logging::log_level::TRACE, "dns: Questions %h \n", size_t(questions));
|
||||
logging::logf(logging::log_level::TRACE, "dns: Answers %h \n", size_t(answers));
|
||||
|
||||
auto flags = dns_header->flags;
|
||||
|
||||
if(flags.qr){
|
||||
logging::logf(logging::log_level::TRACE, "dns: Query\n");
|
||||
} else {
|
||||
logging::logf(logging::log_level::TRACE, "dns: Response\n");
|
||||
}
|
||||
|
||||
//TODO
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
//=======================================================================
|
||||
|
||||
#include "net/udp_layer.hpp"
|
||||
#include "net/dns_layer.hpp"
|
||||
|
||||
#include "kernel_utils.hpp"
|
||||
|
||||
@ -69,7 +70,7 @@ void prepare_packet(network::ethernet::packet& packet, size_t source, size_t tar
|
||||
|
||||
} //end of anonymous namespace
|
||||
|
||||
void network::udp::decode(network::interface_descriptor& /*interface*/, network::ethernet::packet& packet){
|
||||
void network::udp::decode(network::interface_descriptor& interface, network::ethernet::packet& packet){
|
||||
packet.tag(2, packet.index);
|
||||
|
||||
auto* udp_header = reinterpret_cast<header*>(packet.payload + packet.index);
|
||||
@ -84,8 +85,10 @@ void network::udp::decode(network::interface_descriptor& /*interface*/, network:
|
||||
logging::logf(logging::log_level::TRACE, "udp: Target Port %h \n", target_port);
|
||||
logging::logf(logging::log_level::TRACE, "udp: Length %h \n", length);
|
||||
|
||||
packet.index += sizeof(header);
|
||||
|
||||
if(target_port == 53){
|
||||
//TODO DNS decoding
|
||||
network::dns::decode(interface, packet);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user