]> git.meshlink.io Git - catta/blob - avahi-core/internal.h
eb7f14637bd0bc6847b7b47c45b89e55dca15b53
[catta] / avahi-core / internal.h
1 #ifndef foointernalhfoo
2 #define foointernalhfoo
3
4 /***
5   This file is part of avahi.
6
7   avahi is free software; you can redistribute it and/or modify it
8   under the terms of the GNU Lesser General Public License as
9   published by the Free Software Foundation; either version 2.1 of the
10   License, or (at your option) any later version.
11
12   avahi is distributed in the hope that it will be useful, but WITHOUT
13   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15   Public License for more details.
16
17   You should have received a copy of the GNU Lesser General Public
18   License along with avahi; if not, write to the Free Software
19   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20   USA.
21 ***/
22
23 /** A locally registered DNS resource record */
24 typedef struct AvahiEntry AvahiEntry;
25
26 #include <avahi-common/llist.h>
27 #include <avahi-common/watch.h>
28
29 #include "core.h"
30 #include "iface.h"
31 #include "prioq.h"
32 #include "timeeventq.h"
33 #include "announce.h"
34 #include "browse.h"
35 #include "dns.h"
36 #include "rrlist.h"
37 #include "hashmap.h"
38 #include "wide-area.h"
39 #include "multicast-lookup.h"
40 #include "dns-srv-rr.h"
41
42 #define AVAHI_LEGACY_UNICAST_REFLECT_SLOTS_MAX 100
43
44 #define AVAHI_FLAGS_VALID(flags, max) (!((flags) & ~(max)))
45
46 #define AVAHI_RR_HOLDOFF_MSEC 1000
47 #define AVAHI_RR_HOLDOFF_MSEC_RATE_LIMIT 20000
48 #define AVAHI_RR_RATE_LIMIT_COUNT 15
49
50 typedef struct AvahiLegacyUnicastReflectSlot AvahiLegacyUnicastReflectSlot;
51
52 struct AvahiLegacyUnicastReflectSlot {
53     AvahiServer *server;
54
55     uint16_t id, original_id;
56     AvahiAddress address;
57     uint16_t port;
58     int interface;
59     struct timeval elapse_time;
60     AvahiTimeEvent *time_event;
61 };
62
63 struct AvahiEntry {
64     AvahiServer *server;
65     AvahiSEntryGroup *group;
66
67     int dead;
68
69     AvahiPublishFlags flags;
70     AvahiRecord *record;
71     AvahiIfIndex interface;
72     AvahiProtocol protocol;
73
74     AVAHI_LLIST_FIELDS(AvahiEntry, entries);
75     AVAHI_LLIST_FIELDS(AvahiEntry, by_key);
76     AVAHI_LLIST_FIELDS(AvahiEntry, by_group);
77
78     AVAHI_LLIST_HEAD(AvahiAnnouncer, announcers);
79 };
80
81 struct AvahiSEntryGroup {
82     AvahiServer *server;
83     int dead;
84
85     AvahiEntryGroupState state;
86     void* userdata;
87     AvahiSEntryGroupCallback callback;
88
89     unsigned n_probing;
90
91     unsigned n_register_try;
92     struct timeval register_time;
93     AvahiTimeEvent *register_time_event;
94
95     struct timeval established_at;
96
97     AVAHI_LLIST_FIELDS(AvahiSEntryGroup, groups);
98     AVAHI_LLIST_HEAD(AvahiEntry, entries);
99 };
100
101 struct AvahiServer {
102     const AvahiPoll *poll_api;
103
104     AvahiInterfaceMonitor *monitor;
105     AvahiServerConfig config;
106
107     AVAHI_LLIST_HEAD(AvahiEntry, entries);
108     AvahiHashmap *entries_by_key;
109
110     AVAHI_LLIST_HEAD(AvahiSEntryGroup, groups);
111
112     AVAHI_LLIST_HEAD(AvahiSRecordBrowser, record_browsers);
113     AvahiHashmap *record_browser_hashmap;
114     AVAHI_LLIST_HEAD(AvahiSHostNameResolver, host_name_resolvers);
115     AVAHI_LLIST_HEAD(AvahiSAddressResolver, address_resolvers);
116     AVAHI_LLIST_HEAD(AvahiSDomainBrowser, domain_browsers);
117     AVAHI_LLIST_HEAD(AvahiSServiceTypeBrowser, service_type_browsers);
118     AVAHI_LLIST_HEAD(AvahiSServiceBrowser, service_browsers);
119     AVAHI_LLIST_HEAD(AvahiSServiceResolver, service_resolvers);
120     AVAHI_LLIST_HEAD(AvahiSDNSServerBrowser, dns_server_browsers);
121
122     int need_entry_cleanup, need_group_cleanup, need_browser_cleanup;
123
124     /* Used for scheduling RR cleanup */
125     AvahiTimeEvent *cleanup_time_event;
126
127     AvahiTimeEventQueue *time_event_queue;
128
129     char *host_name, *host_name_fqdn, *domain_name;
130
131     int fd_ipv4, fd_ipv6,
132         /* The following two sockets two are used for reflection only */
133         fd_legacy_unicast_ipv4, fd_legacy_unicast_ipv6;
134
135     AvahiWatch *watch_ipv4, *watch_ipv6,
136         *watch_legacy_unicast_ipv4, *watch_legacy_unicast_ipv6;
137
138     AvahiServerState state;
139     AvahiServerCallback callback;
140     void* userdata;
141
142     AvahiSEntryGroup *hinfo_entry_group;
143     AvahiSEntryGroup *browse_domain_entry_group;
144     unsigned n_host_rr_pending;
145
146     /* Used for assembling responses */
147     AvahiRecordList *record_list;
148
149     /* Used for reflection of legacy unicast packets */
150     AvahiLegacyUnicastReflectSlot **legacy_unicast_reflect_slots;
151     uint16_t legacy_unicast_reflect_id;
152
153     /* The last error code */
154     int error;
155
156     /* The local service cookie */
157     uint32_t local_service_cookie;
158
159     AvahiMulticastLookupEngine *multicast_lookup_engine;
160     AvahiWideAreaLookupEngine *wide_area_lookup_engine;
161 };
162
163 void avahi_entry_free(AvahiServer*s, AvahiEntry *e);
164 void avahi_entry_group_free(AvahiServer *s, AvahiSEntryGroup *g);
165
166 void avahi_cleanup_dead_entries(AvahiServer *s);
167
168 void avahi_server_prepare_response(AvahiServer *s, AvahiInterface *i, AvahiEntry *e, int unicast_response, int auxiliary);
169 void avahi_server_prepare_matching_responses(AvahiServer *s, AvahiInterface *i, AvahiKey *k, int unicast_response);
170 void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsPacket *p, const AvahiAddress *a, uint16_t port, int legacy_unicast, int is_probe);
171
172 void avahi_s_entry_group_change_state(AvahiSEntryGroup *g, AvahiEntryGroupState state);
173
174 int avahi_entry_is_commited(AvahiEntry *e);
175
176 void avahi_server_enumerate_aux_records(AvahiServer *s, AvahiInterface *i, AvahiRecord *r, void (*callback)(AvahiServer *s, AvahiRecord *r, int flush_cache, void* userdata), void* userdata);
177
178 void avahi_host_rr_entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void *userdata);
179
180 void avahi_server_decrease_host_rr_pending(AvahiServer *s);
181
182 int avahi_server_set_errno(AvahiServer *s, int error);
183
184 int avahi_server_is_service_local(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, const char *name);
185 int avahi_server_is_record_local(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiRecord *record);
186
187 int avahi_server_add_ptr(
188     AvahiServer *s,
189     AvahiSEntryGroup *g,
190     AvahiIfIndex interface,
191     AvahiProtocol protocol,
192     AvahiPublishFlags flags,
193     uint32_t ttl,
194     const char *name,
195     const char *dest);
196
197 #define AVAHI_CHECK_VALIDITY(server, expression, error) { \
198         if (!(expression)) \
199             return avahi_server_set_errno((server), (error)); \
200 }
201
202 #define AVAHI_CHECK_VALIDITY_RETURN_NULL(server, expression, error) { \
203         if (!(expression)) { \
204             avahi_server_set_errno((server), (error)); \
205             return NULL; \
206         } \
207 }
208
209 #define AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(server, expression, error) {\
210     if (!(expression)) { \
211         ret = avahi_server_set_errno((server), (error)); \
212         goto fail; \
213     } \
214 }
215
216 #define AVAHI_ASSERT_TRUE(expression) { \
217     int __tmp = !!(expression); \
218     assert(__tmp); \
219 }
220
221 #define AVAHI_ASSERT_SUCCESS(expression) { \
222     int __tmp = (expression); \
223     assert(__tmp == 0); \
224 }
225
226 #endif