-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dns: fix name parse/serialization and support escapes (big fix 1/4) #83
base: master
Are you sure you want to change the base?
Conversation
4b302dc
to
1b4d11e
Compare
1b4d11e
to
1bcdd4a
Compare
1bcdd4a
to
e081eb4
Compare
Unfortunately, this is not gonna work. Internal structures that use Current solution (replacing 0x00 by 0xff and 0x2e('.') by 0xfe wont have these issues, even though it will not correctly serialize/deserialize any name that contains Side notes:
knot: |
Most DNS libs don't store the name in presentation format (with literal The current predefined size of 256 in internal structures should still fit any valid DNS name containing any byte 000 to 255 as long as names are not stored in presentation format. Presentation format We could also avoid supporting presentation format entirely and use C escape sequences
Hm I thought the issue with |
Yeah, it makes sense. Not using wire format internally only helps with some functions (makes them easier to read/write about ? e.g. compression), but I am not 100% sure why was this decision made.
I was wondering if we could just use first byte for size. It can store
Yeah, if original content of the wire contains |
I see what you guys are saying, there's no need to use presentation format internally except maybe the log... and we should check the compression functions but I don't think there's a need for strings there either. The best solution to this is stick to wire format internally and use byte arrays instead of strings. DNS wire format has a length byte anyway so we should just stick to that convention. |
Taking another look at this and getting a bit worried -- I wonder what the performance cost is to just change the diff --git a/src/dns.h b/src/dns.h
index 9716d15..bf241b4 100644
--- a/src/dns.h
+++ b/src/dns.h
@@ -6,8 +6,10 @@
#include <stdlib.h>
#include "map.h"
+#define HSK_DNS_MAX_STRING (255 * 4) + 1
+
typedef struct hsk_dns_rr_s {
- char name[256];
+ char name[HSK_DNS_MAX_STRING];
uint16_t type;
uint16_t class;
uint32_t ttl;
@@ -57,7 +59,7 @@ typedef struct {
} hsk_dns_unknown_rd_t;
typedef struct {
- char ns[256];
+ char ns[HSK_DNS_MAX_STRING];
char mbox[256];
uint32_t serial;
uint32_t refresh;
@@ -85,15 +87,15 @@ typedef struct {
} hsk_dns_loc_rd_t;
typedef struct {
- char target[256];
+ char target[HSK_DNS_MAX_STRING];
} hsk_dns_cname_rd_t;
typedef struct {
- char target[256];
+ char target[HSK_DNS_MAX_STRING];
} hsk_dns_dname_rd_t;
typedef struct {
- char ns[256];
+ char ns[HSK_DNS_MAX_STRING];
} hsk_dns_ns_rd_t;
typedef struct {
@@ -167,7 +169,7 @@ typedef struct {
uint32_t expiration;
uint32_t inception;
uint16_t key_tag;
- char signer_name[256];
+ char signer_name[HSK_DNS_MAX_STRING];
size_t signature_len;
uint8_t *signature;
} hsk_dns_rrsig_rd_t;
@@ -185,7 +187,7 @@ typedef struct {
} hsk_dns_rp_rd_t;
typedef struct {
- char next_domain[256];
+ char next_domain[HSK_DNS_MAX_STRING];
size_t type_map_len;
uint8_t *type_map;
} hsk_dns_nsec_rd_t; |
668d733
to
ba7af80
Compare
5fe7c03
to
e820709
Compare
Refactored out of bloated #76
Implement escaped characters when reading and writing names. This means we can lose the weird internal "special bytes"
0xff
and0xfe
which were used to represent\0
and.
respectively, internally, as a "hack" around C strings.So:
...etc
I based this patch on the writeName and readName functions in bns encoding.js
I noticed that knot resolver uses
is_punc()
but JJ used aswitch
with a list of the special characters 🤷Another quirk is that hnsd
hsk_dns_name_serialize()
serves two functions, depending on ifchar *name
is passed, which is report size, or actually write the name. In the PR right now I have basically the same code block twice which seems smelly, could use some inspiration on how or if to optimize that.