1/* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
19#ifndef _dnsextd_h
20#define _dnsextd_h
21
22
23#include <mDNSEmbeddedAPI.h>
24#include <DNSCommon.h>
25#include <GenLinkedList.h>
26#include <sys/types.h>
27#include <sys/socket.h>
28#include <netinet/in.h>
29
30
31#define LLQ_TABLESIZE   1024    // !!!KRS make this dynamically growable
32
33
34typedef enum DNSZoneSpecType
35{
36    kDNSZonePublic,
37    kDNSZonePrivate
38} DNSZoneSpecType;
39
40
41typedef struct DNSZone
42{
43    domainname name;
44    DNSZoneSpecType type;
45    DomainAuthInfo      *   updateKeys; // linked list of keys for signing deletion updates
46    DomainAuthInfo      *   queryKeys;  // linked list of keys for queries
47    struct DNSZone      *   next;
48} DNSZone;
49
50
51typedef struct
52{
53    struct sockaddr_in src;
54    size_t len;
55    DNSZone * zone;
56    mDNSBool isZonePublic;
57    DNSMessage msg;
58    // Note: extra storage for oversized (TCP) messages goes here
59} PktMsg;
60
61// lease table entry
62typedef struct RRTableElem
63{
64    struct RRTableElem *next;
65    struct sockaddr_in cli;   // client's source address
66    long expire;              // expiration time, in seconds since epoch
67    domainname zone;          // from zone field of update message
68    domainname name;          // name of the record
69    CacheRecord rr;           // last field in struct allows for allocation of oversized RRs
70} RRTableElem;
71
72typedef enum
73{
74    RequestReceived = 0,
75    ChallengeSent   = 1,
76    Established     = 2
77} LLQState;
78
79typedef struct AnswerListElem
80{
81    struct AnswerListElem *next;
82    domainname name;
83    mDNSu16 type;
84    CacheRecord *KnownAnswers;  // All valid answers delivered to client
85    CacheRecord *EventList;     // New answers (adds/removes) to be sent to client
86    int refcount;
87    mDNSBool UseTCP;            // Use TCP if UDP would cause truncation
88    pthread_t tid;              // Allow parallel list updates
89} AnswerListElem;
90
91// llq table entry
92typedef struct LLQEntry
93{
94    struct LLQEntry *next;
95    struct sockaddr_in cli;   // clien'ts source address
96    domainname qname;
97    mDNSu16 qtype;
98    mDNSOpaque64 id;
99    LLQState state;
100    mDNSu32 lease;            // original lease, in seconds
101    mDNSs32 expire;           // expiration, absolute, in seconds since epoch
102    AnswerListElem *AnswerList;
103} LLQEntry;
104
105
106typedef void (*EventCallback)( void * context );
107
108typedef struct EventSource
109{
110    EventCallback callback;
111    void                *   context;
112    TCPSocket *         sock;
113    int fd;
114    mDNSBool markedForDeletion;
115    struct  EventSource *   next;
116} EventSource;
117
118
119// daemon-wide information
120typedef struct
121{
122    // server variables - read only after initialization (no locking)
123    struct sockaddr_in addr;            // the address we will bind to
124    struct sockaddr_in llq_addr;        // the address we will receive llq requests on.
125    struct sockaddr_in ns_addr;         // the real ns server address
126    int tcpsd;                          // listening TCP socket for dns requests
127    int udpsd;                          // listening UDP socket for dns requests
128    int tlssd;                          // listening TCP socket for private browsing
129    int llq_tcpsd;                      // listening TCP socket for llq service
130    int llq_udpsd;                      // listening UDP socket for llq service
131    DNameListElem   *   public_names;   // list of public SRV names
132    DNSZone         *   zones;
133
134    // daemon variables - read only after initialization (no locking)
135    mDNSIPPort private_port;           // listening port for private messages
136    mDNSIPPort llq_port;           // listening port for llq
137
138    // lease table variables (locked via mutex after initialization)
139    RRTableElem **table;       // hashtable for records with leases
140    pthread_mutex_t tablelock; // mutex for lease table
141    mDNSs32 nbuckets;          // buckets allocated
142    mDNSs32 nelems;            // elements in table
143
144    // LLQ table variables
145    LLQEntry *LLQTable[LLQ_TABLESIZE];  // !!!KRS change this and RRTable to use a common data structure
146    AnswerListElem *AnswerTable[LLQ_TABLESIZE];
147    int AnswerTableCount;
148    int LLQEventNotifySock;          // Unix domain socket pair - update handling thread writes to EventNotifySock, which wakes
149    int LLQEventListenSock;          // the main thread listening on EventListenSock, indicating that the zone has changed
150
151    GenLinkedList eventSources;     // linked list of EventSource's
152} DaemonInfo;
153
154
155int
156ParseConfig
157(
158    DaemonInfo  *   d,
159    const char  *   file
160);
161
162
163#endif
164