1 #ifndef foointernalhfoo
2 #define foointernalhfoo
5 This file is part of avahi.
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.
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.
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
23 /** A locally registered DNS resource record */
24 typedef struct AvahiEntry AvahiEntry;
26 #include <avahi-common/llist.h>
27 #include <avahi-common/watch.h>
28 #include <avahi-common/timeval.h>
33 #include "timeeventq.h"
39 #include "wide-area.h"
40 #include "multicast-lookup.h"
41 #include "dns-srv-rr.h"
43 #define AVAHI_LEGACY_UNICAST_REFLECT_SLOTS_MAX 100
45 #define AVAHI_FLAGS_VALID(flags, max) (!((flags) & ~(max)))
47 #define AVAHI_RR_HOLDOFF_MSEC 1000
48 #define AVAHI_RR_HOLDOFF_MSEC_RATE_LIMIT 20000
49 #define AVAHI_RR_RATE_LIMIT_COUNT 15
51 typedef struct AvahiLegacyUnicastReflectSlot AvahiLegacyUnicastReflectSlot;
53 struct AvahiLegacyUnicastReflectSlot {
56 uint16_t id, original_id;
60 struct timeval elapse_time;
61 AvahiTimeEvent *time_event;
66 AvahiSEntryGroup *group;
70 AvahiPublishFlags flags;
72 AvahiIfIndex interface;
73 AvahiProtocol protocol;
75 AVAHI_LLIST_FIELDS(AvahiEntry, entries);
76 AVAHI_LLIST_FIELDS(AvahiEntry, by_key);
77 AVAHI_LLIST_FIELDS(AvahiEntry, by_group);
79 AVAHI_LLIST_HEAD(AvahiAnnouncer, announcers);
82 struct AvahiSEntryGroup {
86 AvahiEntryGroupState state;
88 AvahiSEntryGroupCallback callback;
92 unsigned n_register_try;
93 struct timeval register_time;
94 AvahiTimeEvent *register_time_event;
96 struct timeval established_at;
98 AVAHI_LLIST_FIELDS(AvahiSEntryGroup, groups);
99 AVAHI_LLIST_HEAD(AvahiEntry, entries);
103 const AvahiPoll *poll_api;
105 AvahiInterfaceMonitor *monitor;
106 AvahiServerConfig config;
108 AVAHI_LLIST_HEAD(AvahiEntry, entries);
109 AvahiHashmap *entries_by_key;
111 AVAHI_LLIST_HEAD(AvahiSEntryGroup, groups);
113 AVAHI_LLIST_HEAD(AvahiSRecordBrowser, record_browsers);
114 AvahiHashmap *record_browser_hashmap;
115 AVAHI_LLIST_HEAD(AvahiSHostNameResolver, host_name_resolvers);
116 AVAHI_LLIST_HEAD(AvahiSAddressResolver, address_resolvers);
117 AVAHI_LLIST_HEAD(AvahiSDomainBrowser, domain_browsers);
118 AVAHI_LLIST_HEAD(AvahiSServiceTypeBrowser, service_type_browsers);
119 AVAHI_LLIST_HEAD(AvahiSServiceBrowser, service_browsers);
120 AVAHI_LLIST_HEAD(AvahiSServiceResolver, service_resolvers);
121 AVAHI_LLIST_HEAD(AvahiSDNSServerBrowser, dns_server_browsers);
123 int need_entry_cleanup, need_group_cleanup, need_browser_cleanup;
125 /* Used for scheduling RR cleanup */
126 AvahiTimeEvent *cleanup_time_event;
128 AvahiTimeEventQueue *time_event_queue;
130 char *host_name, *host_name_fqdn, *domain_name;
132 int fd_ipv4, fd_ipv6,
133 /* The following two sockets two are used for reflection only */
134 fd_legacy_unicast_ipv4, fd_legacy_unicast_ipv6;
136 AvahiWatch *watch_ipv4, *watch_ipv6,
137 *watch_legacy_unicast_ipv4, *watch_legacy_unicast_ipv6;
139 AvahiServerState state;
140 AvahiServerCallback callback;
143 AvahiSEntryGroup *hinfo_entry_group;
144 AvahiSEntryGroup *browse_domain_entry_group;
145 unsigned n_host_rr_pending;
147 /* Used for assembling responses */
148 AvahiRecordList *record_list;
150 /* Used for reflection of legacy unicast packets */
151 AvahiLegacyUnicastReflectSlot **legacy_unicast_reflect_slots;
152 uint16_t legacy_unicast_reflect_id;
154 /* The last error code */
157 /* The local service cookie */
158 uint32_t local_service_cookie;
160 AvahiMulticastLookupEngine *multicast_lookup_engine;
161 AvahiWideAreaLookupEngine *wide_area_lookup_engine;
164 void avahi_entry_free(AvahiServer*s, AvahiEntry *e);
165 void avahi_entry_group_free(AvahiServer *s, AvahiSEntryGroup *g);
167 void avahi_cleanup_dead_entries(AvahiServer *s);
169 void avahi_server_prepare_response(AvahiServer *s, AvahiInterface *i, AvahiEntry *e, int unicast_response, int auxiliary);
170 void avahi_server_prepare_matching_responses(AvahiServer *s, AvahiInterface *i, AvahiKey *k, int unicast_response);
171 void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsPacket *p, const AvahiAddress *a, uint16_t port, int legacy_unicast, int is_probe);
173 void avahi_s_entry_group_change_state(AvahiSEntryGroup *g, AvahiEntryGroupState state);
175 int avahi_entry_is_commited(AvahiEntry *e);
177 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);
179 void avahi_host_rr_entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void *userdata);
181 void avahi_server_decrease_host_rr_pending(AvahiServer *s);
183 int avahi_server_set_errno(AvahiServer *s, int error);
185 int avahi_server_is_service_local(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, const char *name);
186 int avahi_server_is_record_local(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiRecord *record);
188 int avahi_server_add_ptr(
191 AvahiIfIndex interface,
192 AvahiProtocol protocol,
193 AvahiPublishFlags flags,
198 #define AVAHI_CHECK_VALIDITY(server, expression, error) { \
200 return avahi_server_set_errno((server), (error)); \
203 #define AVAHI_CHECK_VALIDITY_RETURN_NULL(server, expression, error) { \
204 if (!(expression)) { \
205 avahi_server_set_errno((server), (error)); \
210 #define AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(server, expression, error) {\
211 if (!(expression)) { \
212 ret = avahi_server_set_errno((server), (error)); \
217 #define AVAHI_ASSERT_TRUE(expression) { \
218 int __tmp = !!(expression); \
222 #define AVAHI_ASSERT_SUCCESS(expression) { \
223 int __tmp = (expression); \
224 assert(__tmp == 0); \