aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMarvin Borner2020-11-15 18:28:21 +0100
committerMarvin Borner2020-11-15 18:28:21 +0100
commit72143cff9dbde52d6165742e43b1d20b13bb23e7 (patch)
treeeb0adb8aacc77b4a3ab062788e8f015683be36bd /kernel
parent0621c44e439bedf034399e1bff139ef506039eba (diff)
Added DNS errors
Diffstat (limited to 'kernel')
-rw-r--r--kernel/drivers/interrupts.c8
-rw-r--r--kernel/features/net.c10
-rw-r--r--kernel/inc/net.h11
3 files changed, 24 insertions, 5 deletions
diff --git a/kernel/drivers/interrupts.c b/kernel/drivers/interrupts.c
index dd10ac6..29ff55d 100644
--- a/kernel/drivers/interrupts.c
+++ b/kernel/drivers/interrupts.c
@@ -13,8 +13,8 @@
* IDT
*/
-struct idt_entry idt[256] = { 0 };
-struct idt_ptr idt_ptr = { 0 };
+static struct idt_entry idt[256] = { 0 };
+static struct idt_ptr idt_ptr = { 0 };
void idt_set_gate(u8 num, u32 base, u16 sel, u8 flags)
{
@@ -45,7 +45,7 @@ void idt_install()
* IRQ
*/
-void (*irq_routines[16])(struct regs *) = { 0 };
+static void (*irq_routines[16])(struct regs *) = { 0 };
// Install IRQ handler
void irq_install_handler(int irq, void (*handler)(struct regs *r))
@@ -120,7 +120,7 @@ void irq_install(void)
* ISR
*/
-void (*isr_routines[256])(struct regs *) = { 0 };
+static void (*isr_routines[256])(struct regs *) = { 0 };
const char *isr_exceptions[32] = { "Division By Zero",
"Debug",
diff --git a/kernel/features/net.c b/kernel/features/net.c
index 82009dd..679f06a 100644
--- a/kernel/features/net.c
+++ b/kernel/features/net.c
@@ -248,6 +248,7 @@ static void ip_send_packet(u32 dst, void *data, int len, u8 prot)
packet->version_ihl = ((0x4 << 4) | (0x5 << 0));
packet->length = (u16)sizeof(*packet) + (u16)len;
packet->id = htons(1); // TODO: IP fragmentation
+ /* packet->flags_fragment = htons(1); */
packet->ttl = 64;
packet->protocol = prot;
packet->src = htonl(current_ip_addr);
@@ -395,6 +396,13 @@ static void icmp_handle_packet(struct icmp_packet *request_packet, u32 dst)
static void dns_handle_packet(struct dns_packet *packet)
{
print("DNS!\n");
+ u16 flags = htons(packet->flags);
+ u8 reply_code = flags & 0xf;
+ if (reply_code != DNS_NOERROR) {
+ printf("DNS error: %d\n", reply_code);
+ return;
+ }
+
u8 *start = &packet->data[1] + strlen((char *)&packet->data[1]);
printf("TTL of %s: %ds\n", &packet->data[1], (u32)start[14]);
u8 *ip = &start[17];
@@ -433,7 +441,7 @@ static void dhcp_handle_packet(struct dhcp_packet *packet)
// enum tcp_state { TCP_LISTEN, TCP_SYN_SENT, TCP_SYN_RECIEVED, TCP_ESTABLISHED, TCP_FIN_WAIT_1, TCP_FIN_WAIT_2, TCP_CLOSE_WAIT, TCP_CLOSING, TCP_LAST_ACK, TCP_TIME_WAIT, TCP_CLOSED };
#define http_res "HTTP/1.1 200\r\nContent-Length: 14\r\nConnection: close\r\n\r\n<h1>Hallo</h1>"
-#define http_req "GET / HTTP/1.1\r\nHost: marvinborner.de\r\n\r\n"
+#define http_req "GET / HTTP/1.1\r\nHost: google.de\r\n\r\n"
static void tcp_handle_packet(struct tcp_packet *packet, u32 dst, int len)
{
printf("TCP Port: %d\n", ntohs(packet->dst_port));
diff --git a/kernel/inc/net.h b/kernel/inc/net.h
index f9986e0..1111f22 100644
--- a/kernel/inc/net.h
+++ b/kernel/inc/net.h
@@ -39,6 +39,17 @@
#define DHCP_REPLY 2
#define DHCP_TRANSACTION_IDENTIFIER 0x18122002
+#define DNS_NOERROR 0
+#define DNS_FORMERR 1
+#define DNS_SERVFAIL 2
+#define DNS_NXDOMAIN 3
+#define DNS_NOTIMP 4
+#define DNS_REFUSED 5
+#define DNS_YXDOMAIN 6
+#define DNS_XRRSET 7
+#define DNS_NOTAUTH 8
+#define DNS_NOTZONE 9
+
#define HARDWARE_TYPE_ETHERNET 0x01
// Hardcoded ports - TODO!