Earlier quoted context omitted.
I found that after I had already written a lot of that code. I haven't had much reason to go back and change it, but any PR's if someone wants to do it, would be accepted.
What about simply replacing all "== 0b..." with "!= 0"? That would already be a good improvement, both in terms of DRY and readability, without the need of adding another dependency.
A year of Rust and DNS
61–70 of 109 posts
Re: A year of Rust and DNS
#62The only technical comment I have is that it continues to be amazing to me that destructuring binary data is so stupidly verbose in so many languages. I think C and Erlang are the only two languages that got this right.
Re: A year of Rust and DNS
#63Earlier quoted context omitted.
I thought DJB generally donates his code to the public domain. Hard to be "friendlier" than that.
Public domain code is actually illegal in some places, if I recall correctly
Re: A year of Rust and DNS
#64,----
| %% extract dns-header fields from a raw packet.
| parse_dns_header(raw_packet) ->
| | ID:16,
| QR:1, OPCODE:4, AA:1, TC:1, RD:1, RA:1, Z:3, RCODE:4,
| QDCOUNT:16,
| ANCOUNT:16,
| NSCOUNT:16, ARCOUNT:16,
| Tail/binary
| >> = raw_packet,
|
| {#dns_header_record {
| id = ID,
| qr = QR, opcode = OPCODE, aa = AA, tc = TC, rd = RD, ra = RA, z = Z, rcode = RCODE,
| qdcount = QDCOUNT,
| ancount = ANCOUNT,
| nscount = NSCOUNT,
| arcount = ARCOUNT
| }, Tail}.
|
`----
almost verbatim 'transliteration' of sec:4.1.1 of 1035 :)
Re: A year of Rust and DNS
#65Love the idea of reimplementing DNS in Rust. Would love to see more efforts like this so that we have secure-by-design language implementation of core security services. But BIND isn't just failing because "it's written in C", it's failing because it's written in terrible C. That said, "terrible C" is probably most every C routine written by someone with less than 10 years of solid low level experience, so "writing g…
Well, djb's dns has bugs (zone corruption, lack of duplicate outbound surpression leading to trivial poisoning, query pool flushing) and missing essentials (IPv6, and most DNS since 2007). Some of these bugs were paid out in fact. There are patches, but not everything is fixed, and not all the patches play well together. The lack of maintenance and an upstream has caused some distros to consider dropping for security…
Re: A year of Rust and DNS
#66Nit: Rust doesn't prevent memory leak.
It makes it much more difficult. In fact safe rust provides similar guarantees to garbage collected languages as the heap-allocated classes will clean themselves up.
Also, remember mem::forget() is not unsafe
I'm pointing this out because I don't want people to have wrong expectation of Rust. Rust doesn't prevent memory leak. Rust doesn't consider memory leak to be "unsafe". Even the Rust team themselves have pointed this out multiple times.
Somehow people are still repeating that Rust can rid you of memory leaks. And I'm downvoted just because I'm pointing out facts. Sigh.
Re: A year of Rust and DNS
#67Earlier quoted context omitted.
What about simply replacing all "== 0b..." with "!= 0"? That would already be a good improvement, both in terms of DRY and readability, without the need of adding another dependency.
It wouldn't be the same thing. For instance x & 0b11 != 0 can return true for multiple values of x, 0b10 and 0b01 respectively.
Re: A year of Rust and DNS
#68with erlang you can parse the dns-header like so: ,---- | %% extract dns-header fields from a raw packet. | parse_dns_header(raw_packet) -> | | ID:16, | QR:1, OPCODE:4, AA:1, TC:1, RD:1, RA:1, Z:3, RCODE:4, | QDCOUNT:16, | ANCOUNT:16, | NSCOUNT:16, ARCOUNT:16, | Tail/binary | >> = raw_packet, | | {#dns_header_record { | id = ID, | qr = QR, opcode = OPCODE, aa = AA, tc = TC, rd = RD, ra = RA, z = Z, rcode = RCODE, | q…
I wish more programming languages would make an effort like this to optimize readability and be self-documenting.
Re: A year of Rust and DNS
#69with erlang you can parse the dns-header like so: ,---- | %% extract dns-header fields from a raw packet. | parse_dns_header(raw_packet) -> | | ID:16, | QR:1, OPCODE:4, AA:1, TC:1, RD:1, RA:1, Z:3, RCODE:4, | QDCOUNT:16, | ANCOUNT:16, | NSCOUNT:16, ARCOUNT:16, | Tail/binary | >> = raw_packet, | | {#dns_header_record { | id = ID, | qr = QR, opcode = OPCODE, aa = AA, tc = TC, rd = RD, ra = RA, z = Z, rcode = RCODE, | q…
Syntax-wise this is brilliant, I think. Very similar to how a good parsing-combinator library looks almost like the grammar it is parsing. I wish more programming languages would make an effort like this to optimize readability and be self-documenting.
yup. getting from an ascii art representation of the pdu, to something like this should be fairly trivial :) only if writing fsm's were that easy ;)
Re: A year of Rust and DNS
#70with erlang you can parse the dns-header like so: ,---- | %% extract dns-header fields from a raw packet. | parse_dns_header(raw_packet) -> | | ID:16, | QR:1, OPCODE:4, AA:1, TC:1, RD:1, RA:1, Z:3, RCODE:4, | QDCOUNT:16, | ANCOUNT:16, | NSCOUNT:16, ARCOUNT:16, | Tail/binary | >> = raw_packet, | | {#dns_header_record { | id = ID, | qr = QR, opcode = OPCODE, aa = AA, tc = TC, rd = RD, ra = RA, z = Z, rcode = RCODE, | q…
parse_dns_header(raw_packet) ->
> = raw_packet,
Also for readers, this does depend on customisable (per-segment/field) defaults: `ID:16` is a shorthand for `ID:16/big-unsigned-integer-unit:1` aka "16-bits wide segment parsed as an unsigned integer in big endian"