Post AXUi6jXeTyZ8rsDid6 by shane_kerr@fosstodon.org
 (DIR) More posts by shane_kerr@fosstodon.org
 (DIR) Post #AXUICAnDzdHo1eRBU8 by shane_kerr@fosstodon.org
       2023-07-08T09:42:15Z
       
       0 likes, 0 repeats
       
       I've been thinking about the best way to store DNS names in a database. I wrote up some of the ideas here:https://gitlab.com/shane_kerr/dns-names/tl/dr:1. convert to lowercase2. reverse the order of labels3. convert each character to hexSo "www.example.net" becomes "6e6574.6578616d706c65.777777". I *think* that this is probably the best approach, unless your database actually has support for DNS names.#dns
       
 (DIR) Post #AXUICBtHuZjLQkHXZg by farrokhi@unix.family
       2023-07-08T14:40:14Z
       
       0 likes, 0 repeats
       
       @shane_kerr why not just reverse the string?
       
 (DIR) Post #AXUICCcJDBk7gNLUkS by bortzmeyer@mastodon.gougere.fr
       2023-07-08T14:47:14Z
       
       0 likes, 0 repeats
       
       @farrokhi @shane_kerr [Troll] What if the name contains a dot? Handling it as a string will create trouble.
       
 (DIR) Post #AXUICCpmP6WCM9eFkG by shane_kerr@fosstodon.org
       2023-07-08T09:45:57Z
       
       0 likes, 0 repeats
       
       There's also some Python code there to demonstrate the conversions, although of course the approaches are language-neutral.#dns #python
       
 (DIR) Post #AXUIE2wS9daqFreByS by bortzmeyer@mastodon.gougere.fr
       2023-07-08T14:47:38Z
       
       0 likes, 0 repeats
       
       @shane_kerr What about IDN?
       
 (DIR) Post #AXUIKriwGF7dURZs8W by bortzmeyer@mastodon.gougere.fr
       2023-07-08T14:48:51Z
       
       0 likes, 0 repeats
       
       @shane_kerr I once wrote a SQL schema where the table contained only labels, not complete names, plus reference to the parent. Cool to find all the children. Less cool when trying to gather the labels for www.phy.cam.ac.uk.
       
 (DIR) Post #AXUMETfLC968xF6WH2 by duponin@udongein.xyz
       2023-07-08T15:32:13.013870Z
       
       0 likes, 0 repeats
       
       @bortzmeyer @shane_kerr may I naively ask why not simply storing DNS rrset as a string? "www.example.net","CNAME","example.net" (that’s 3 columns)
       
 (DIR) Post #AXUPFYwPMnfnT3IQim by shane_kerr@fosstodon.org
       2023-07-08T16:06:19Z
       
       0 likes, 0 repeats
       
       @bortzmeyer I talk about IDN in the README.md, but basically for storage I think converting to Punycode when possible is the best approach. Punycode seems to convert to lower case so it kind of replaces that step. (I am not an expert with localization though, that's for sure.)Since Unicode to Punycode is not always reversible, probably it makes sense to store both the original text version and the Punycode -> reversed -> hexadecimal version.
       
 (DIR) Post #AXUSVH7pfleqi0p8nQ by bortzmeyer@mastodon.gougere.fr
       2023-07-08T16:42:46Z
       
       1 likes, 0 repeats
       
       @duponin @shane_kerr It is less efficient for some requests such as "finding all children of a node".
       
 (DIR) Post #AXUi6jXeTyZ8rsDid6 by shane_kerr@fosstodon.org
       2023-07-08T19:37:36Z
       
       0 likes, 0 repeats
       
       @bortzmeyer Yeah I considered that, and also keeping labels in a separate table and storing names as something like:create table label (  label_id int primary key,  val bytea unique);create table name (  name_id primary key,  label int not null references label(label_id),  parent int references name(name_id),  is_ent bool not null);Depending on the data being stored it should be space-efficient, but it's not handy, and storage is cheap. 😆
       
 (DIR) Post #AXUisw9usKahtp6T6u by shane_kerr@fosstodon.org
       2023-07-08T19:46:20Z
       
       0 likes, 0 repeats
       
       @bortzmeyer @duponin It's also basically impossible to get a sorted list of names just storing the names in presentation format, which is important for DNSSEC, both signing or answering queries.
       
 (DIR) Post #AXUmWJdTp3kdrrOsd6 by gjherbiet@mamot.fr
       2023-07-08T20:27:03Z
       
       0 likes, 0 repeats
       
       @bortzmeyer @shane_kerr Interesting approach. May also be a case of over-design. I am myself wondering if having a table for RRSETs (with NAME, CLASS, TYPE and TTL) and then a table of RR values referring it would make thinks like ensuring coherent TTLs, CNAME restriction, etc. easier or just more complex…