chiark / gitweb /
resolved: rework logic so that we can share transactions between queries of different...
[elogind.git] / src / resolve / resolved-dns-packet.h
index 67c7bc3dfc62efc99d6510217150d69e28f941d7..ab46b33c48157130aa3e0c16784ba48e2c06d10a 100644 (file)
@@ -30,6 +30,16 @@ typedef struct DnsPacket DnsPacket;
 #include "sparse-endian.h"
 #include "hashmap.h"
 #include "resolved-dns-rr.h"
+#include "resolved-dns-question.h"
+#include "resolved-dns-answer.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;
@@ -54,19 +64,28 @@ struct DnsPacketHeader {
 
 struct DnsPacket {
         int n_ref;
-        int ifindex;
+        DnsProtocol protocol;
         size_t size, allocated, rindex;
+        void *_data; /* don't access directly, use DNS_PACKET_DATA()! */
         Hashmap *names; /* For name compression */
-        DnsResourceRecord **rrs;
-        void *data;
+
+        /* Parsed data */
+        DnsQuestion *question;
+        DnsAnswer *answer;
+
+        /* 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) {
         if (_unlikely_(!p))
                 return NULL;
 
-        if (p->data)
-                return p->data;
+        if (p->_data)
+                return p->_data;
 
         return ((uint8_t*) p) + ALIGN(sizeof(DnsPacket));
 }
@@ -100,8 +119,8 @@ static inline unsigned DNS_PACKET_RRCOUNT(DnsPacket *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);
@@ -124,13 +143,13 @@ int dns_packet_read_uint16(DnsPacket *p, uint16_t *ret, size_t *start);
 int dns_packet_read_uint32(DnsPacket *p, uint32_t *ret, size_t *start);
 int dns_packet_read_string(DnsPacket *p, char **ret, size_t *start);
 int dns_packet_read_name(DnsPacket *p, char **ret, size_t *start);
-int dns_packet_read_key(DnsPacket *p, DnsResourceKey *ret, size_t *start);
+int dns_packet_read_key(DnsPacket *p, DnsResourceKey **ret, size_t *start);
 int dns_packet_read_rr(DnsPacket *p, DnsResourceRecord **ret, size_t *start);
 
 void dns_packet_rewind(DnsPacket *p, size_t idx);
 
 int dns_packet_skip_question(DnsPacket *p);
-int dns_packet_extract_rrs(DnsPacket *p);
+int dns_packet_extract(DnsPacket *p);
 
 enum {
         DNS_RCODE_SUCCESS = 0,
@@ -157,3 +176,9 @@ enum {
 
 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 } })