add pktinfo to rx path
[project/mdnsd.git] / dns.h
1 /*
2  * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 2.1
6  * as published by the Free Software Foundation
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13
14 #ifndef _DNS_H__
15 #define _DNS_H__
16
17 #include <stdint.h>
18
19 #define FLAG_RESPONSE           0x8000
20 #define FLAG_AUTHORATIVE        0x0400
21
22 #define TYPE_A                  0x0001
23 #define TYPE_PTR                0x000C
24 #define TYPE_TXT                0x0010
25 #define TYPE_AAAA               0x001c
26 #define TYPE_SRV                0x0021
27 #define TYPE_ANY                0x00ff
28
29 #define IS_COMPRESSED(x)        ((x & 0xc0) == 0xc0)
30
31 #define MCAST_ADDR              "224.0.0.251"
32 #define MCAST_ADDR6             "ff02::fb"
33 #define MCAST_PORT              5353
34
35 #define CLASS_FLUSH             0x8000
36 #define CLASS_IN                0x0001
37
38 #define MAX_NAME_LEN            8096
39 #define MAX_DATA_LEN            8096
40
41 #define C_DNS_SD                "_services._dns-sd._udp.local"
42
43 struct dns_header {
44         uint16_t id;
45         uint16_t flags;
46         uint16_t questions;
47         uint16_t answers;
48         uint16_t authority;
49         uint16_t additional;
50 };
51
52 struct dns_srv_data {
53         uint16_t priority;
54         uint16_t weight;
55         uint16_t port;
56 } __attribute__((packed, aligned(2)));
57
58 struct dns_answer {
59         uint16_t type;
60         uint16_t class;
61         uint32_t ttl;
62         uint16_t rdlength;
63 } __attribute__((packed, aligned(2)));
64
65 struct dns_question {
66         uint16_t type;
67         uint16_t class;
68 } __attribute__((packed, aligned(2)));
69
70 struct interface;
71 extern int cfg_proto;
72
73 void dns_send_question(struct interface *iface, const char *question, int type);
74 void dns_init_answer(void);
75 void dns_add_answer(int type, const uint8_t *rdata, uint16_t rdlength, int ttl);
76 void dns_send_answer(struct interface *iface, const char *answer);
77 const char* dns_type_string(uint16_t type);
78 void dns_handle_packet(struct interface *iface, uint8_t *buf, int len);
79
80 #endif