You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Ntk_andna_and_dns 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. {{{
  2. ANDNS PROTOCOL
  3. INDEX:
  4. 0 - Introduction
  5. 1 - Notations
  6. 2 - Packet Headers
  7. 3 - Query Type
  8. 4 - Query Realm
  9. 5 - Rcode
  10. 6 - Questions
  11. 7 - Answers
  12. 8 - Compression
  13. 0. - INTRODUCTION -
  14. This document describes the protocol used to communicate with ANDNA.
  15. This protocol is used also to make query in internet realm.
  16. So, we can query for `google.it` in internet, or for `depausceve`
  17. in the netsukuku net.
  18. In the case of internet queries, the dns_wrapper will contact the
  19. dns-servers specified in /etc/resolv.conf when ntkd is loaded.
  20. 1. - NOTATIONS -
  21. In the next section, we represent a byte with this graphic:
  22. 1 2 3 4 5 6 7 8
  23. +--+--+--+--+--+--+--+--+
  24. | |
  25. +--+--+--+--+--+--+--+--+
  26. The numbers represent the bits
  27. Let's show two bytes:
  28. 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
  29. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  30. | | |
  31. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  32. 2. - HEADERS -
  33. Headers are 4-byte long, and the format is:
  34. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  35. | ID | R|
  36. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  37. |QR| P| Z| QT | ANCOUNT |I | NK| RCODE |
  38. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  39. where:
  40. ID = It's a 2-byte value which identifies the query.
  41. ID is choosed in a random way and the future
  42. answers must have the same ID.
  43. R = Recursion bit. If set, SNSD queries that have
  44. a hostname as resolution will be resolved (if
  45. possible).
  46. QR = 0 implies that this packet contains a question
  47. 1 if the packets contains answers
  48. P = If the query is h2ip and ntk-related, P specifies
  49. the protocol service:
  50. 0 for TCP
  51. 1 for UDP
  52. P has to be zero otherwise.
  53. Z = zlib compression. If z=1, the packet contents,
  54. headers excluded, are zlib-compressed. See
  55. Section 8.
  56. QT = Query Type. See below.
  57. Note: answers must leave this field unchanged.
  58. ANCOUNT = Answer Count. This field is set only if QR=1,
  59. ie if this packet contains answers.
  60. ANCOUNT is the number of answers which belongs
  61. to this packet.
  62. I = Ip-version bit. Specifies the ip version for the
  63. packet contents. All addresses contained in the
  64. packet are:
  65. if I==0 IPv4 addresses (4-bytes)
  66. if I==1 Ipv6 addresses (16-bytes)
  67. This bit is useful only for questions. The server
  68. will reply "NO SUCH DOMAIN" if his node is running
  69. with a different ip-version.
  70. Otherwise, only IPs of the same family will be
  71. returned.
  72. NK = Netsukuku bit. With this field, you can specify
  73. the query realm.
  74. If NK=1, the realm is netsukuku.
  75. If NK=2, the realm is internet.
  76. If NK=0, the packet is not encoded with this
  77. protocol, but with standard DNS protocol.
  78. To specify realms with DNS protocol, see below.
  79. Note: answers must leave this field unchanged.
  80. RCODE = This is the result of a query.
  81. RCODE has to be 0 if this packet contains a
  82. question.
  83. In the case of errors, ANCOUNT has to be 0.
  84. 3. - QUERY TYPE -
  85. There are different kind of questions:
  86. QTYPE = 0
  87. This is the classic resolution `hostname -> ip`.
  88. A gethostbyname.
  89. Note: this type of query is used also for SNSD
  90. resolution (see `NTK_RFC 0009`).
  91. You can specify a service.
  92. So, the general way to represent this query is:
  93. hostname:service -> ip
  94. If you don't specify a service, the 0-service
  95. will be used.
  96. Example: if you want to discover which address is
  97. hosting the http service of hostname `depausceve`,
  98. you have to formule this query:
  99. depausceve:80
  100. See below how to formule queries.
  101. QTYPE = 1
  102. This is a reverse resolution: `ip -> host`.
  103. QTYPE =2
  104. This is a global query: all services for the
  105. hostname will be answered.
  106. The query realm has to be Ntk.
  107. 4. - QUERY REALMS -
  108. A query can be formulated to find some object in the
  109. netsukuku net or in internet.
  110. Maybe you want to know the ip of `google.it`, but you
  111. have to specify where: internet or netsukuku?
  112. If you use ANDNS protocol, you specify this with NK
  113. bit (See the HEADERS SECTION).
  114. If you use DNS protocol, you have to formule the query
  115. with some suffix: if you ask for `google.it.int` (or
  116. google.it.INT), the question is made in internet.
  117. If you ask for `google.it.ntk` (or `google.it.NTK)
  118. the question is made in netsukuku.
  119. If you don't specify any suffix, the default realm
  120. is Netsukuku Realm
  121. The dns_wrapper first search for a suffix, understanding
  122. the correct realm.
  123. If the question does not have any suffix, the query
  124. will be made in the default realm.
  125. Otherwise, dns_wrapper removes this suffix and
  126. resolves the query without it.
  127. 5. - RCODE -
  128. This is the answer report.
  129. It's always 0 if the packet carries a question.
  130. Possible values, in the case of an answer, are:
  131. RCODE = 0 No Error.
  132. This answer contains answers.
  133. The number of ANSWERS is ANCOUNT (see
  134. HEADERS SECTION).
  135. RCODE = 1 Interpretation Error.
  136. The server did not understand your query.
  137. In other words, your question is malformed.
  138. RCODE = 2 Server Fail.
  139. The server did encounter some error processing
  140. your question. Your question is good.
  141. RCODE = 3 No Such Domain
  142. The object of your question does not exist.
  143. RCODE = 4 Not Implemented
  144. This type of query is not implemented yet
  145. in this server.
  146. RCODE = 5 Refused
  147. The server refuse to talk with you.
  148. Note: this expression is always true:
  149. (RCODE XOR ANCOUNT)
  150. ie, if RCODE contains some error (RCODE!=0), there is
  151. not answer in this packet. If RCODE is 0 (no error),
  152. the packet contains some answer.
  153. 6. - QUESTIONS -
  154. We have to switch the value QTYPE against realm.
  155. - Case QTYPE = 0 (h2ip) AND Realm=NTK
  156. The format of the question is:
  157. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  158. | SERVICE |
  159. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  160. | |
  161. | |
  162. | |
  163. | HOSTNAME |
  164. | HASH |
  165. | (HH) |
  166. | |
  167. | |
  168. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  169. where:
  170. SERVICE is a 2-byte field and represents the SNSD service
  171. value (see `NTK_RFC 0009`).
  172. HH is the 16-bytes hostname hash.
  173. - Case QTYPE = 0 (h2ip) AND Realm=INET
  174. The format of the question is:
  175. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  176. | SERVICE |
  177. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  178. | RDLENGTH |
  179. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  180. | |
  181. \ \
  182. \ RDATA \
  183. | |
  184. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  185. where:
  186. SERVICE is a 2-byte field and represents the SNSD service
  187. value (see `NTK_RFC 0009`). At this moment, for INET
  188. resolutions, the service is limited to value 25
  189. - TCP is assumed - or 0.
  190. RDLENGTH is the RDATA len
  191. RDATA is a hostname string, such that:
  192. strlen(RDATA)=RDLENGTH
  193. - Case QTYPE = 1 (ip2h).
  194. The format of the question is:
  195. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  196. | |
  197. / RDATA /
  198. / /
  199. | |
  200. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  201. where:
  202. RDATA is an IP in the binary format.
  203. The length of the field - ie the family address (4 or 6) -
  204. depends on the bit `I' in the headers section.
  205. - Case QTYPE = 2 (global query).
  206. The format of the question is:
  207. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  208. | |
  209. | |
  210. | |
  211. | HOSTNAME |
  212. | HASH |
  213. | (HH) |
  214. | |
  215. | |
  216. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  217. where:
  218. HH is the 16-bytes hostname hash.
  219. 7. - ANSWERS -
  220. The format of answers is:
  221. CASE QTYPE=0 (h2ip)
  222. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  223. | | T| WG | PRIO |
  224. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  225. | |
  226. / RDATA /
  227. / /
  228. | |
  229. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  230. where:
  231. T is set if this answer carries an IP.
  232. T is 0 if the answer carries a hostname hash.
  233. WG is the weigth of an answer (see `NTK_RFC 0009`)
  234. PRIO the priority (see `NTK_RFC 0009`)
  235. RDATA is a binary ip address (His family (and his length) is specified
  236. in the headers bit `I') or a hostname hash).
  237. CASE QTYPE=1 (ip2h)
  238. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  239. | RDLENGTH |
  240. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  241. | |
  242. / RDATA /
  243. / /
  244. | |
  245. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  246. where:
  247. RDLENGTH is the strlen of RDATA (RDATA is a hostname).
  248. RDATA the hostname resolution.
  249. CASE QTYPE=2 (global query)
  250. If QTYPE=2, there is a extra header field before answers:
  251. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  252. | ANCOUNT |
  253. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  254. The two bytes are the number of answers that the query
  255. produced. After the two bytes.
  256. Note: the ANCOUNT field on main headers has to be 1 if
  257. RCODE=0, 0 otherwise.
  258. The two extra bytes are the real number of answers in the
  259. case of QTYPE=2.
  260. After the two bytes, this is the format for each answer:
  261. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  262. | M| T| P| WG | PRIO |
  263. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  264. | SERVICE |
  265. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  266. | |
  267. / DATA /
  268. / /
  269. | |
  270. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  271. where T is the type of the DATA.
  272. T is:
  273. T = 0 Hostname
  274. T = 1 Ip
  275. M is set if T is set, and specifies that this is the MAIN_IP
  276. of the hostname.
  277. P is The protocol: Tcp if 0, UDP if 1.
  278. If T=1, the ip version is specified in main headers, in the
  279. field I.
  280. If T=0, the format of data is:
  281. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  282. | |
  283. | |
  284. | |
  285. | HOSTNAME |
  286. | HASH |
  287. | (HH) |
  288. | |
  289. | |
  290. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  291. where HH is the 16 bytes hash of SNSD hostname.
  292. If T=1, the format of data is:
  293. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  294. | |
  295. / RDATA /
  296. / /
  297. | |
  298. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  299. where RDATA is the binary IP and the length of his contents
  300. depends on the field I of main headers (4 in IPv4, 16 in IPv6).
  301. 8. - COMPRESSION -
  302. The format of a compressed packet is:
  303. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  304. | ID | R|
  305. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  306. |QR| P| Z| QT | ANCOUNT |I | NK| RCODE |
  307. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  308. | |
  309. | USIZE |
  310. | |
  311. | |
  312. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  313. | |
  314. / DATA /
  315. / /
  316. | |
  317. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  318. Headers remain uncompressed. The packet contents, question and
  319. answers, are compressed with zlib. The buffer obtained with the
  320. compression is DATA.
  321. USIZE is the original size of packet contents (question and
  322. answers).
  323. If a packet is compressed, then Z=1.
  324. }}}