#include "hashmap.h"
#include "resolved-dns-rr.h"
+typedef enum DnsProtocol {
+ DNS_PROTOCOL_DNS,
+ DNS_PROTOCOL_MDNS,
+ DNS_PROTOCOL_LLMNR,
+ _DNS_PROTOCOL_MAX,
+ _DNS_PROTOCOL_INVALID = -1
+} DnsProtocol;
+
struct DnsPacketHeader {
uint16_t id;
be16_t flags;
/* The various DNS protocols deviate in how large a packet can grow,
but the TCP transport has a 16bit size field, hence that appears to
- be the maximum. */
+ be the absolute maximum. */
#define DNS_PACKET_SIZE_MAX 0xFFFF
+
+/* RFC 1035 say 512 is the maximum, for classic unicast DNS */
+#define DNS_PACKET_UNICAST_SIZE_MAX 512
+
#define DNS_PACKET_SIZE_START 512
struct DnsPacket {
int n_ref;
- int ifindex;
+ DnsProtocol protocol;
size_t size, allocated, rindex;
- Hashmap *names; /* For name compression */
void *data;
+ Hashmap *names; /* For name compression */
+ DnsResourceRecord **rrs;
+
+ /* Packet reception meta data */
+ int ifindex;
+ int family;
+ union in_addr_union sender, destination;
+ uint32_t ttl;
};
static inline uint8_t* DNS_PACKET_DATA(DnsPacket *p) {
((uint16_t) !!cd << 4) | \
((uint16_t) (rcode & 15)))
+static inline unsigned DNS_PACKET_RRCOUNT(DnsPacket *p) {
+ return
+ (unsigned) DNS_PACKET_ANCOUNT(p) +
+ (unsigned) DNS_PACKET_NSCOUNT(p) +
+ (unsigned) DNS_PACKET_ARCOUNT(p);
+}
-int dns_packet_new(DnsPacket **p, size_t mtu);
-int dns_packet_new_query(DnsPacket **p, size_t mtu);
+int dns_packet_new(DnsPacket **p, DnsProtocol protocol, size_t mtu);
+int dns_packet_new_query(DnsPacket **p, DnsProtocol protocol, size_t mtu);
DnsPacket *dns_packet_ref(DnsPacket *p);
DnsPacket *dns_packet_unref(DnsPacket *p);
void dns_packet_rewind(DnsPacket *p, size_t idx);
int dns_packet_skip_question(DnsPacket *p);
+int dns_packet_extract_rrs(DnsPacket *p);
enum {
DNS_RCODE_SUCCESS = 0,
const char* dns_rcode_to_string(int i) _const_;
int dns_rcode_from_string(const char *s) _pure_;
+
+const char* dns_protocol_to_string(DnsProtocol p) _const_;
+DnsProtocol dns_protocol_from_string(const char *s) _pure_;
+
+#define LLMNR_MULTICAST_IPV4_ADDRESS ((struct in_addr) { .s_addr = htobe32(224U << 24 | 252U) })
+#define LLMNR_MULTICAST_IPV6_ADDRESS ((struct in6_addr) { .s6_addr = { 0xFF, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03 } })