1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
31 #define LLQ_TABLESIZE 1024 // !!!KRS make this dynamically growable
34 typedef enum DNSZoneSpecType
41 typedef struct DNSZone
45 DomainAuthInfo
* updateKeys
; // linked list of keys for signing deletion updates
46 DomainAuthInfo
* queryKeys
; // linked list of keys for queries
47 struct DNSZone
* next
;
53 struct sockaddr_in src
;
56 mDNSBool isZonePublic
;
58 // Note: extra storage for oversized (TCP) messages goes here
62 typedef struct RRTableElem
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
79 typedef struct AnswerListElem
81 struct AnswerListElem
*next
;
84 CacheRecord
*KnownAnswers
; // All valid answers delivered to client
85 CacheRecord
*EventList
; // New answers (adds/removes) to be sent to client
87 mDNSBool UseTCP
; // Use TCP if UDP would cause truncation
88 pthread_t tid
; // Allow parallel list updates
92 typedef struct LLQEntry
94 struct LLQEntry
*next
;
95 struct sockaddr_in cli
; // clien'ts source address
100 mDNSu32 lease
; // original lease, in seconds
101 mDNSs32 expire
; // expiration, absolute, in seconds since epoch
102 AnswerListElem
*AnswerList
;
106 typedef void (*EventCallback
)( void * context
);
108 typedef struct EventSource
110 EventCallback callback
;
114 mDNSBool markedForDeletion
;
115 struct EventSource
* next
;
119 // daemon-wide information
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
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
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
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
151 GenLinkedList eventSources
; // linked list of EventSource's