1#ifndef fooifacehfoo
2#define fooifacehfoo
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
23typedef struct AvahiInterfaceMonitor AvahiInterfaceMonitor;
24typedef struct AvahiInterfaceAddress AvahiInterfaceAddress;
25typedef struct AvahiInterface AvahiInterface;
26typedef struct AvahiHwInterface AvahiHwInterface;
27
28#include <avahi-common/llist.h>
29#include <avahi-common/address.h>
30#include <avahi-common/defs.h>
31
32#include "internal.h"
33#include "cache.h"
34#include "response-sched.h"
35#include "query-sched.h"
36#include "probe-sched.h"
37#include "dns.h"
38#include "announce.h"
39#include "browse.h"
40#include "querier.h"
41
42#include "llmnr-querier.h"
43#include "llmnr-query-sched.h"
44#include "llmnr-response.h"
45
46#include "verify.h"
47
48#ifdef HAVE_NETLINK
49#include "iface-linux.h"
50#elif defined(HAVE_PF_ROUTE)
51#include "iface-pfroute.h"
52#else
53typedef struct AvahiInterfaceMonitorOSDep AvahiInterfaceMonitorOSDep;
54struct AvahiInterfaceMonitorOSDep {
55
56    unsigned query_addr_seq, query_link_seq;
57
58    enum {
59        LIST_IFACE,
60        LIST_ADDR,
61        LIST_DONE
62    } list;
63};
64#endif
65
66#define AVAHI_MAC_ADDRESS_MAX 32
67
68struct AvahiInterfaceMonitor {
69    AvahiServer *server;
70    AvahiHashmap *hashmap;
71
72    AVAHI_LLIST_HEAD(AvahiInterface, interfaces);
73    AVAHI_LLIST_HEAD(AvahiHwInterface, hw_interfaces);
74
75    int list_complete;
76    AvahiInterfaceMonitorOSDep osdep;
77};
78
79struct AvahiHwInterface {
80    AvahiInterfaceMonitor *monitor;
81
82    AVAHI_LLIST_FIELDS(AvahiHwInterface, hardware);
83
84    char *name;
85    AvahiIfIndex index;
86    int flags_ok;
87
88    unsigned mtu;
89
90    uint8_t mac_address[AVAHI_MAC_ADDRESS_MAX];
91    size_t mac_address_size;
92
93    AvahiSEntryGroup *entry_group;
94
95    /* Packet rate limiting */
96    struct timeval ratelimit_begin;
97    unsigned ratelimit_counter;
98
99    AVAHI_LLIST_HEAD(AvahiInterface, interfaces);
100};
101
102struct AvahiInterface {
103    AvahiInterfaceMonitor *monitor;
104    AvahiHwInterface *hardware;
105
106    AVAHI_LLIST_FIELDS(AvahiInterface, interface);
107    AVAHI_LLIST_FIELDS(AvahiInterface, by_hardware);
108
109    AvahiProtocol protocol;
110    AVAHI_LLIST_HEAD(AvahiInterfaceAddress, addresses);
111
112    struct {
113        int announcing;
114        AvahiAddress local_mcast_address;
115        int mcast_joined;
116
117        AvahiCache *cache;
118
119        AvahiQueryScheduler *query_scheduler;
120        AvahiResponseScheduler * response_scheduler;
121        AvahiProbeScheduler *probe_scheduler;
122
123        AVAHI_LLIST_HEAD(AvahiAnnouncer, announcers);
124
125        AvahiHashmap *queriers_by_key;
126        AVAHI_LLIST_HEAD(AvahiQuerier, queriers);
127    } mdns;
128
129    struct {
130        int verifying;
131        AvahiAddress local_llmnr_address;
132        int llmnr_joined;
133
134        AvahiLLMNRQueryScheduler *query_scheduler;
135        AvahiLLMNRResponseScheduler *response_scheduler;
136
137        AvahiHashmap *queryjobs_by_key;
138
139        AVAHI_LLIST_HEAD(AvahiLLMNRQueryJob, queryjobs);
140        /*AVAHI_LLIST_HEAD(AvahiEntry, entries);*/
141        AVAHI_LLIST_HEAD(AvahiLLMNREntryVerify, verifiers);
142    } llmnr;
143};
144
145struct AvahiInterfaceAddress {
146    AvahiInterfaceMonitor *monitor;
147    AvahiInterface *interface;
148
149    AVAHI_LLIST_FIELDS(AvahiInterfaceAddress, address);
150
151    AvahiAddress address;
152    unsigned prefix_len;
153
154    int global_scope;
155    int deprecated;
156
157    AvahiSEntryGroup *entry_mdns_group;
158    AvahiSEntryGroup *entry_llmnr_group;
159};
160
161AvahiInterfaceMonitor *avahi_interface_monitor_new(AvahiServer *server);
162void avahi_interface_monitor_free(AvahiInterfaceMonitor *m);
163
164int avahi_interface_monitor_init_osdep(AvahiInterfaceMonitor *m);
165void avahi_interface_monitor_free_osdep(AvahiInterfaceMonitor *m);
166void avahi_interface_monitor_sync(AvahiInterfaceMonitor *m);
167
168typedef void (*AvahiInterfaceMonitorWalkCallback)(AvahiInterfaceMonitor *m, AvahiInterface *i, void* userdata);
169void avahi_interface_monitor_walk(AvahiInterfaceMonitor *m, AvahiIfIndex idx, AvahiProtocol protocol, AvahiInterfaceMonitorWalkCallback callback, void* userdata);
170int avahi_dump_caches(AvahiInterfaceMonitor *m, AvahiDumpCallback callback, void* userdata);
171
172void avahi_interface_monitor_update_rrs(AvahiInterfaceMonitor *m, int remove_rrs);
173int avahi_address_is_local(AvahiInterfaceMonitor *m, const AvahiAddress *a);
174void avahi_interface_monitor_check_relevant(AvahiInterfaceMonitor *m, AvahiPublishProtocol proto);
175
176/* AvahiHwInterface */
177
178AvahiHwInterface *avahi_hw_interface_new(AvahiInterfaceMonitor *m, AvahiIfIndex idx);
179void avahi_hw_interface_free(AvahiHwInterface *hw, int send_goodbye);
180
181void avahi_hw_interface_update_rrs(AvahiHwInterface *hw, int remove_rrs);
182void avahi_hw_interface_check_relevant(AvahiHwInterface *hw, AvahiPublishProtocol proto);
183
184AvahiHwInterface* avahi_interface_monitor_get_hw_interface(AvahiInterfaceMonitor *m, int idx);
185
186/* AvahiInterface */
187
188AvahiInterface* avahi_interface_new(AvahiInterfaceMonitor *m, AvahiHwInterface *hw, AvahiProtocol protocol);
189void avahi_interface_free(AvahiInterface *i, int send_goodbye);
190
191void avahi_interface_update_rrs(AvahiInterface *i, int remove_rrs);
192void avahi_interface_check_relevant(AvahiInterface *i, AvahiPublishProtocol proto);
193int avahi_interface_is_relevant(AvahiInterface *i);
194
195void avahi_interface_send_packet(AvahiInterface *i, AvahiDnsPacket *p, AvahiPublishProtocol proto);
196void avahi_interface_send_packet_unicast(AvahiInterface *i, AvahiDnsPacket *p, const AvahiAddress *a, uint16_t port, AvahiPublishProtocol proto);
197int avahi_interface_post_query(AvahiInterface *i, AvahiKey *k, int immediately, unsigned *ret_id);
198int avahi_interface_withraw_query(AvahiInterface *i, unsigned id);
199int avahi_interface_post_response(AvahiInterface *i, AvahiRecord *record, int flush_cache, const AvahiAddress *querier, int immediately);
200int avahi_interface_post_probe(AvahiInterface *i, AvahiRecord *p, int immediately);
201
202/*LLMNR*/
203int avahi_schedule_llmnr_response_job(AvahiLLMNRResponseScheduler *s, AvahiDnsPacket *p, const AvahiAddress *querier, uint16_t port);
204int avahi_interface_post_llmnr_query(AvahiInterface *i, AvahiLLMNRQuery *lq, int im);
205int avahi_interface_withdraw_llmnr_query(AvahiInterface *i, unsigned id);
206/* /LLMNR */
207
208int avahi_interface_match(AvahiInterface *i, AvahiIfIndex idx, AvahiProtocol protocol);
209int avahi_interface_address_on_link(AvahiInterface *i, const AvahiAddress *a);
210int avahi_interface_has_address(AvahiInterfaceMonitor *m, AvahiIfIndex iface, const AvahiAddress *a);
211
212AvahiInterface* avahi_interface_monitor_get_interface(AvahiInterfaceMonitor *m, AvahiIfIndex idx, AvahiProtocol protocol);
213
214/* AvahiInterfaceAddress */
215
216AvahiInterfaceAddress *avahi_interface_address_new(AvahiInterfaceMonitor *m, AvahiInterface *i, const AvahiAddress *addr, unsigned prefix_len);
217void avahi_interface_address_free(AvahiInterfaceAddress *a);
218
219void avahi_interface_address_update_rrs(AvahiInterfaceAddress *a, int remove_rrs);
220int avahi_interface_address_is_relevant(AvahiInterfaceAddress *a);
221
222AvahiInterfaceAddress* avahi_interface_monitor_get_address(AvahiInterfaceMonitor *m, AvahiInterface *i, const AvahiAddress *raddr);
223
224AvahiIfIndex avahi_find_interface_for_address(AvahiInterfaceMonitor *m, const AvahiAddress *a);
225
226#endif
227