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