summaryrefslogtreecommitdiffstats
path: root/avahi-core/server.h
blob: f4c7d92e7a81a8358fd0f382961360fb0b3fdf64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef fooserverhfoo
#define fooserverhfoo

/* $Id$ */

/***
  This file is part of avahi.
 
  avahi is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation; either version 2.1 of the
  License, or (at your option) any later version.
 
  avahi is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
  Public License for more details.
 
  You should have received a copy of the GNU Lesser General Public
  License along with avahi; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  USA.
***/

#include <avahi-common/llist.h>
#include "core.h"
#include "iface.h"
#include "prioq.h"
#include "timeeventq.h"
#include "announce.h"
#include "browse.h"
#include "dns.h"
#include "rrlist.h"

#define AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS 100

typedef struct AvahiLegacyUnicastReflectSlot AvahiLegacyUnicastReflectSlot;

struct AvahiLegacyUnicastReflectSlot {
    AvahiServer *server;
    
    guint16 id, original_id;
    AvahiAddress address;
    guint16 port;
    gint interface;
    struct timeval elapse_time;
    AvahiTimeEvent *time_event;
};

struct AvahiEntry {
    AvahiServer *server;
    AvahiEntryGroup *group;

    gboolean dead;
    
    AvahiEntryFlags flags;
    AvahiRecord *record;
    AvahiIfIndex interface;
    AvahiProtocol protocol;

    AVAHI_LLIST_FIELDS(AvahiEntry, entries);
    AVAHI_LLIST_FIELDS(AvahiEntry, by_key);
    AVAHI_LLIST_FIELDS(AvahiEntry, by_group);
    
    AVAHI_LLIST_HEAD(AvahiAnnouncement, announcements);
};

struct AvahiEntryGroup {
    AvahiServer *server;
    gboolean dead;

    AvahiEntryGroupState state;
    gpointer userdata;
    AvahiEntryGroupCallback callback;

    guint n_probing;
    
    guint n_register_try;
    struct timeval register_time;
    AvahiTimeEvent *register_time_event;
    
    AVAHI_LLIST_FIELDS(AvahiEntryGroup, groups);
    AVAHI_LLIST_HEAD(AvahiEntry, entries);
};

struct AvahiServer {
    GMainContext *context;
    AvahiInterfaceMonitor *monitor;

    AvahiServerConfig config;

    AVAHI_LLIST_HEAD(AvahiEntry, entries);
    GHashTable *entries_by_key;

    AVAHI_LLIST_HEAD(AvahiEntryGroup, 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;
    
    AvahiTimeEventQueue *time_event_queue;
    
    gchar *host_name, *host_name_fqdn, *domain_name;

    gint 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;

    AvahiServerState state;
    AvahiServerCallback callback;
    gpointer userdata;

    AvahiEntryGroup *hinfo_entry_group;
    AvahiEntryGroup *browse_domain_entry_group;
    guint 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;

    gint error;
};

gboolean avahi_server_entry_match_interface(AvahiEntry *e, AvahiInterface *i);

void avahi_server_post_query(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiKey *key);

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_entry_group_change_state(AvahiEntryGroup *g, AvahiEntryGroupState state);

gboolean avahi_entry_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_host_rr_entry_group_callback(AvahiServer *s, AvahiEntryGroup *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);

#endif