X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Fserver.h;h=8b3b9dae2a9b3d57acdcfecb0a6eda5bc2a2e55f;hb=3adbda2cd5be48b7c630325f0f92e315d7eb2cfb;hp=6572fbb69e9983ade674cf7d3cf4113be455274c;hpb=0632e854728e8e64552ae08f90852d4a2658539e;p=catta diff --git a/avahi-core/server.h b/avahi-core/server.h index 6572fbb..8b3b9da 100644 --- a/avahi-core/server.h +++ b/avahi-core/server.h @@ -22,38 +22,52 @@ USA. ***/ +#include +#include + +/** A locally registered DNS resource record */ +typedef struct AvahiEntry AvahiEntry; + #include "core.h" #include "iface.h" #include "prioq.h" -#include "llist.h" #include "timeeventq.h" #include "announce.h" #include "browse.h" #include "dns.h" #include "rrlist.h" +#include "hashmap.h" +#include "wide-area.h" +#include "multicast-lookup.h" #define AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS 100 +#define AVAHI_FLAGS_VALID(flags, max) (!((flags) & ~(max))) + +#define AVAHI_RR_HOLDOFF_MSEC 1000 +#define AVAHI_RR_HOLDOFF_MSEC_RATE_LIMIT 60000 +#define AVAHI_RR_RATE_LIMIT_COUNT 15 + typedef struct AvahiLegacyUnicastReflectSlot AvahiLegacyUnicastReflectSlot; struct AvahiLegacyUnicastReflectSlot { AvahiServer *server; - guint16 id, original_id; + uint16_t id, original_id; AvahiAddress address; - guint16 port; - gint interface; - GTimeVal elapse_time; + uint16_t port; + int interface; + struct timeval elapse_time; AvahiTimeEvent *time_event; }; struct AvahiEntry { AvahiServer *server; - AvahiEntryGroup *group; + AvahiSEntryGroup *group; - gboolean dead; + int dead; - AvahiEntryFlags flags; + AvahiPublishFlags flags; AvahiRecord *record; AvahiIfIndex interface; AvahiProtocol protocol; @@ -62,98 +76,133 @@ struct AvahiEntry { AVAHI_LLIST_FIELDS(AvahiEntry, by_key); AVAHI_LLIST_FIELDS(AvahiEntry, by_group); - AVAHI_LLIST_HEAD(AvahiAnnouncement, announcements); + AVAHI_LLIST_HEAD(AvahiAnnouncer, announcers); }; -struct AvahiEntryGroup { +struct AvahiSEntryGroup { AvahiServer *server; - gboolean dead; + int dead; AvahiEntryGroupState state; - gpointer userdata; - AvahiEntryGroupCallback callback; + void* userdata; + AvahiSEntryGroupCallback callback; - guint n_probing; + unsigned n_probing; - guint n_register_try; - GTimeVal register_time; + unsigned n_register_try; + struct timeval register_time; AvahiTimeEvent *register_time_event; + + struct timeval established_at; - AVAHI_LLIST_FIELDS(AvahiEntryGroup, groups); + AVAHI_LLIST_FIELDS(AvahiSEntryGroup, groups); AVAHI_LLIST_HEAD(AvahiEntry, entries); }; struct AvahiServer { - GMainContext *context; + const AvahiPoll *poll_api; + AvahiInterfaceMonitor *monitor; - AvahiServerConfig config; AVAHI_LLIST_HEAD(AvahiEntry, entries); - GHashTable *entries_by_key; + AvahiHashmap *entries_by_key; - AVAHI_LLIST_HEAD(AvahiEntryGroup, groups); + AVAHI_LLIST_HEAD(AvahiSEntryGroup, groups); - AVAHI_LLIST_HEAD(AvahiRecordBrowser, record_browsers); - GHashTable *record_browser_hashtable; - AVAHI_LLIST_HEAD(AvahiHostNameResolver, host_name_resolvers); - AVAHI_LLIST_HEAD(AvahiAddressResolver, address_resolvers); - AVAHI_LLIST_HEAD(AvahiDomainBrowser, domain_browsers); - AVAHI_LLIST_HEAD(AvahiServiceTypeBrowser, service_type_browsers); - AVAHI_LLIST_HEAD(AvahiServiceBrowser, service_browsers); - AVAHI_LLIST_HEAD(AvahiServiceResolver, service_resolvers); - AVAHI_LLIST_HEAD(AvahiDNSServerBrowser, dns_server_browsers); - - gboolean need_entry_cleanup, need_group_cleanup, need_browser_cleanup; + AVAHI_LLIST_HEAD(AvahiSRecordBrowser, record_browsers); + AvahiHashmap *record_browser_hashmap; + AVAHI_LLIST_HEAD(AvahiSHostNameResolver, host_name_resolvers); + AVAHI_LLIST_HEAD(AvahiSAddressResolver, address_resolvers); + AVAHI_LLIST_HEAD(AvahiSDomainBrowser, domain_browsers); + AVAHI_LLIST_HEAD(AvahiSServiceTypeBrowser, service_type_browsers); + AVAHI_LLIST_HEAD(AvahiSServiceBrowser, service_browsers); + AVAHI_LLIST_HEAD(AvahiSServiceResolver, service_resolvers); + AVAHI_LLIST_HEAD(AvahiSDNSServerBrowser, dns_server_browsers); + + int need_entry_cleanup, need_group_cleanup, need_browser_cleanup; AvahiTimeEventQueue *time_event_queue; - gchar *host_name, *host_name_fqdn, *domain_name; + char *host_name, *host_name_fqdn, *domain_name; - gint fd_ipv4, fd_ipv6, + int fd_ipv4, fd_ipv6, /* The following two sockets two are used for reflection only */ fd_legacy_unicast_ipv4, fd_legacy_unicast_ipv6; - GPollFD pollfd_ipv4, pollfd_ipv6, pollfd_legacy_unicast_ipv4, pollfd_legacy_unicast_ipv6; - GSource *source; + AvahiWatch *watch_ipv4, *watch_ipv6, + *watch_legacy_unicast_ipv4, *watch_legacy_unicast_ipv6; AvahiServerState state; AvahiServerCallback callback; - gpointer userdata; + void* userdata; - AvahiEntryGroup *hinfo_entry_group; - AvahiEntryGroup *browse_domain_entry_group; - guint n_host_rr_pending; + AvahiSEntryGroup *hinfo_entry_group; + AvahiSEntryGroup *browse_domain_entry_group; + unsigned n_host_rr_pending; /* Used for assembling responses */ AvahiRecordList *record_list; /* Used for reflection of legacy unicast packets */ AvahiLegacyUnicastReflectSlot **legacy_unicast_reflect_slots; - guint16 legacy_unicast_reflect_id; + uint16_t legacy_unicast_reflect_id; + + /* The last error code */ + int error; + + /* The local service cookie */ + uint32_t local_service_cookie; - gint error; + AvahiMulticastLookupEngine *multicast_lookup_engine; + AvahiWideAreaLookupEngine *wide_area_lookup_engine; }; -gboolean avahi_server_entry_match_interface(AvahiEntry *e, AvahiInterface *i); +void avahi_entry_free(AvahiServer*s, AvahiEntry *e); +void avahi_entry_group_free(AvahiServer *s, AvahiSEntryGroup *g); -void avahi_server_post_query(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiKey *key); +void avahi_cleanup_dead_entries(AvahiServer *s); -void avahi_server_prepare_response(AvahiServer *s, AvahiInterface *i, AvahiEntry *e, gboolean unicast_response, gboolean auxiliary); -void avahi_server_prepare_matching_responses(AvahiServer *s, AvahiInterface *i, AvahiKey *k, gboolean unicast_response); -void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsPacket *p, const AvahiAddress *a, guint16 port, gboolean legacy_unicast, gboolean is_probe); +void avahi_server_prepare_response(AvahiServer *s, AvahiInterface *i, AvahiEntry *e, int unicast_response, int auxiliary); +void avahi_server_prepare_matching_responses(AvahiServer *s, AvahiInterface *i, AvahiKey *k, int unicast_response); +void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsPacket *p, const AvahiAddress *a, uint16_t port, int legacy_unicast, int is_probe); -void avahi_entry_group_change_state(AvahiEntryGroup *g, AvahiEntryGroupState state); +void avahi_s_entry_group_change_state(AvahiSEntryGroup *g, AvahiEntryGroupState state); -gboolean avahi_entry_commited(AvahiEntry *e); +int avahi_entry_is_commited(AvahiEntry *e); -void avahi_server_enumerate_aux_records(AvahiServer *s, AvahiInterface *i, AvahiRecord *r, void (*callback)(AvahiServer *s, AvahiRecord *r, gboolean flush_cache, gpointer userdata), gpointer userdata); +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); -void avahi_host_rr_entry_group_callback(AvahiServer *s, AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata); +void avahi_host_rr_entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void *userdata); void avahi_server_decrease_host_rr_pending(AvahiServer *s); void avahi_server_increase_host_rr_pending(AvahiServer *s); -gint avahi_server_set_errno(AvahiServer *s, gint error); +int avahi_server_set_errno(AvahiServer *s, int error); + +int avahi_server_add_ptr( + AvahiServer *s, + AvahiSEntryGroup *g, + AvahiIfIndex interface, + AvahiProtocol protocol, + AvahiPublishFlags flags, + uint32_t ttl, + const char *name, + const char *dest); + + +#define AVAHI_CHECK_VALIDITY_RETURN_NULL(server, expression, error) { \ + if (!(expression)) { \ + avahi_server_set_errno((server), (error)); \ + return NULL; \ + } \ +} + +#define AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(server, expression, error) {\ + if (!(expression)) { \ + ret = avahi_server_set_errno((server), (error)); \ + goto fail; \ + } \ +} #endif