chiark / gitweb /
WIP dns transport packets etc. wip.ip-over-dns
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 17 Aug 2011 20:51:40 +0000 (21:51 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Aug 2011 15:44:06 +0000 (16:44 +0100)
dns-transp-client.c [new file with mode: 0644]
dns-transp-common.h
dns-transp-server.c

diff --git a/dns-transp-client.c b/dns-transp-client.c
new file mode 100644 (file)
index 0000000..deec7b6
--- /dev/null
@@ -0,0 +1,48 @@
+/**/
+
+uint8_t qid[2];
+
+#define PKT_PREPEND_START(pe, size, body) do{          \
+    assert((pe)->ptr - (pe)->buf >= (size));           \
+    const uint8_t *pkt_prepend_orig = (pe)->ptr;       \
+    uint8_t *pkt = (pe)->ptr -= (size);                        \
+    { body; }                                          \
+    assert(pkt == pkt_prepend_orig);                   \
+  }while(0)
+
+#define PKT_ADDB(byte) (*pkt++ = (byte))
+#define PKT_ADDW(word) (*pkt++ = ((w) >> 8), *pkt++ = (w))
+
+#define DNS_HDRLEN (6*2)
+
+void dnsqueryenc_start(struct dnspacketenc *pe,
+                      int mydompathlen, const char *mydompath) {
+    dnspacketenc_start(pe);
+    
+    PKT_PREPEND(pe, 4, {
+       PKT_ADDW(QTYPE_CNAME);
+       PKT_ADDW(QCLASS_IN);
+    });
+
+    return dnsdomainenc_start(&pe->dom, pe->buf,
+                             pe->ptr - pe->buf - DNS_HDRLEN,
+                             mydompathlen, mydompath);
+}
+
+void dnsqueryenc_finish(uint16_t qid, const uint8_t **result, int *reslen) {
+    pe->ptr = dnsdomainenc_getresult(&pe->dom);
+
+    PKT_PREPEND(pe, DNS_HDRLEN, {
+       PKT_ADDW(qid);
+       PKT_ADDB(0x00); /* QR=0(q); Opcode=QUERY; !AA,!TC,!RD */
+       PKT_ADDB(0x00); /* !RA; Z; RCODE=NOERROR */
+       PKT_ADDW(0x01); /* QDCOUNT=1 */
+       PKT_ADDW(0x00); /* ANCOUNT=0 */
+       PKT_ADDW(0x00); /* NSCOUNT=0 */
+       PKT_ADDW(0x00); *hdr++ = 0x00; /* ARCOUNT=0 */
+    });
+
+    *result = pe->ptr;
+    *reslen = (pe->buf + MAX_DNSPACKET_BYTES) - pe->ptr;
+}
+
index 53f6a73f0849c0f7e691640f00b5b0dce544fa0a..9b25f26cd731dbef924f0f3969dc53ac213210b1 100644 (file)
@@ -36,6 +36,12 @@ struct dnsdomainenc {
     int labremain;
 };
 
+struct dnspacketenc {
+    uint8_t buf[MAX_DNSPACKET_BYTES];
+    uint8_t *ptr;
+    struct dnsdomainenc dom;
+};
+
 /*
  * The only legal calling sequence is this:
  *   start
index fd52b8a2fc6ddcc51d282efdb48d4d0e532ff7fb..b822932dc666f1ecc449139425d4550dc2881338 100644 (file)
@@ -114,4 +114,13 @@ struct dns_server {
  * 4a. create assoc packet
  *    look up {clientaddr,clientnonce} in clientinit
  *    if not then create an assoc
- *    
+ */
+
+
+
+
+void incoming_packet(const uint8_t pkt, int len) {
+    if (len < DNS_HDRLEN)
+       return badpkt("shorter than dns header");
+    
+    uint16_t id =