packet-parsing #1
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "packet-parsing"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This change adds basic DNS query header parsing. It should be really fast because it simply casts the byte buffer directly into the header struct, but i had to make some changes to the field order in the struct definition to make this work. Details in src/dns_request.c
@ -7,1 +7,4 @@struct DNSPacketHeader *header;};struct DNSRequest *parse_dns_query(struct DNSPacketBuffer *pb);recommend typedef'ing this so that you can use DNSRequest as a first class type name and not need to add "struct" everywhere.
@ -1,5 +1,5 @@#pragma once#define UDP_PORT 53#define UDP_PORT 1053I think there is a way to leave this at 53 and then use compiler flags to redefine it. Might be a good idea.
Or you could use an IFNDEF clause to have one port for debug builds and one port for release builds based on whether or not cmake is compiling this with debug info.
@ -2,3 +2,4 @@#include <stdio.h>#include <stdlib.h>struct DNSPacketBuffer *new_dns_packet_buffer()What is the point of this getter? I could collapse it down to one line:
If you implement a typedef for this that one liner gets even more concise:
Also, I think it is a really bad idea to have malloc called in scattered functions like this. One honest recommendation I can make is to make sure that the point in code where you need memory should be the same place that you both allocate and free it.
In essence: as much as possible every function that calls malloc should also call free.
I have also seen larger applications keep pools associated with lifetimes. NGINX and NGINX Unit both keep a memory pool to allocate out of attached to a request object. Maybe a simpler implementation could be to create a request_resources struct that tracks shared state through the request processing pipeline. You could store pointers to all your malloc()'ed stuff there and then at the very end implement logic that calls free() on everything attached to the request.
@ -5,2 +4,4 @@#define PB_SIZE 512#define PB_OUT_OF_BOUNDS 9999;struct DNSPacketBuffer {Im used to seeing underscores instead of camelcase in C projects, but thats just an opinion.
@ -8,4 +9,4 @@size_t pos;};struct DNSPacketBuffer *new_dns_packet_buffer();I think both of the structs in this file should be typedef'ed so that you dont need to write 'struct' everywhere.
Looks cool. I am excited to see how it goes!
Do update your alog dependency to the version on this server though please. I will be deleting the gitlab at some point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.