]> git.meshlink.io Git - catta/blob - src/iface.h
rename everything avahi to catta
[catta] / src / iface.h
1 #ifndef fooifacehfoo
2 #define fooifacehfoo
3
4 /***
5   This file is part of catta.
6
7   catta 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   catta 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 catta; 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 CattaInterfaceMonitor CattaInterfaceMonitor;
24 typedef struct CattaInterfaceAddress CattaInterfaceAddress;
25 typedef struct CattaInterface CattaInterface;
26 typedef struct CattaHwInterface CattaHwInterface;
27
28 #include <catta/llist.h>
29 #include <catta/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 CattaInterfaceMonitorOSDep CattaInterfaceMonitorOSDep;
47 struct CattaInterfaceMonitorOSDep {
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 CATTA_MAC_ADDRESS_MAX 32
60
61 struct CattaInterfaceMonitor {
62     CattaServer *server;
63     CattaHashmap *hashmap;
64
65     CATTA_LLIST_HEAD(CattaInterface, interfaces);
66     CATTA_LLIST_HEAD(CattaHwInterface, hw_interfaces);
67
68     int list_complete;
69     CattaInterfaceMonitorOSDep osdep;
70 };
71
72 struct CattaHwInterface {
73     CattaInterfaceMonitor *monitor;
74
75     CATTA_LLIST_FIELDS(CattaHwInterface, hardware);
76
77     char *name;
78     CattaIfIndex index;
79     int flags_ok;
80
81     unsigned mtu;
82
83     uint8_t mac_address[CATTA_MAC_ADDRESS_MAX];
84     size_t mac_address_size;
85
86     CattaSEntryGroup *entry_group;
87
88     /* Packet rate limiting */
89     struct timeval ratelimit_begin;
90     unsigned ratelimit_counter;
91
92     CATTA_LLIST_HEAD(CattaInterface, interfaces);
93 };
94
95 struct CattaInterface {
96     CattaInterfaceMonitor *monitor;
97     CattaHwInterface *hardware;
98
99     CATTA_LLIST_FIELDS(CattaInterface, interface);
100     CATTA_LLIST_FIELDS(CattaInterface, by_hardware);
101
102     CattaProtocol protocol;
103     int announcing;
104     CattaAddress local_mcast_address;
105     int mcast_joined;
106
107     CattaCache *cache;
108
109     CattaQueryScheduler *query_scheduler;
110     CattaResponseScheduler * response_scheduler;
111     CattaProbeScheduler *probe_scheduler;
112
113     CATTA_LLIST_HEAD(CattaInterfaceAddress, addresses);
114     CATTA_LLIST_HEAD(CattaAnnouncer, announcers);
115
116     CattaHashmap *queriers_by_key;
117     CATTA_LLIST_HEAD(CattaQuerier, queriers);
118 };
119
120 struct CattaInterfaceAddress {
121     CattaInterfaceMonitor *monitor;
122     CattaInterface *interface;
123
124     CATTA_LLIST_FIELDS(CattaInterfaceAddress, address);
125
126     CattaAddress address;
127     unsigned prefix_len;
128
129     int global_scope;
130     int deprecated;
131
132     CattaSEntryGroup *entry_group;
133 };
134
135 CattaInterfaceMonitor *catta_interface_monitor_new(CattaServer *server);
136 void catta_interface_monitor_free(CattaInterfaceMonitor *m);
137
138 int catta_interface_monitor_init_osdep(CattaInterfaceMonitor *m);
139 void catta_interface_monitor_free_osdep(CattaInterfaceMonitor *m);
140 void catta_interface_monitor_sync(CattaInterfaceMonitor *m);
141
142 typedef void (*CattaInterfaceMonitorWalkCallback)(CattaInterfaceMonitor *m, CattaInterface *i, void* userdata);
143 void catta_interface_monitor_walk(CattaInterfaceMonitor *m, CattaIfIndex idx, CattaProtocol protocol, CattaInterfaceMonitorWalkCallback callback, void* userdata);
144 int catta_dump_caches(CattaInterfaceMonitor *m, CattaDumpCallback callback, void* userdata);
145
146 void catta_interface_monitor_update_rrs(CattaInterfaceMonitor *m, int remove_rrs);
147 int catta_address_is_local(CattaInterfaceMonitor *m, const CattaAddress *a);
148 void catta_interface_monitor_check_relevant(CattaInterfaceMonitor *m);
149
150 /* CattaHwInterface */
151
152 CattaHwInterface *catta_hw_interface_new(CattaInterfaceMonitor *m, CattaIfIndex idx);
153 void catta_hw_interface_free(CattaHwInterface *hw, int send_goodbye);
154
155 void catta_hw_interface_update_rrs(CattaHwInterface *hw, int remove_rrs);
156 void catta_hw_interface_check_relevant(CattaHwInterface *hw);
157
158 CattaHwInterface* catta_interface_monitor_get_hw_interface(CattaInterfaceMonitor *m, int idx);
159
160 /* CattaInterface */
161
162 CattaInterface* catta_interface_new(CattaInterfaceMonitor *m, CattaHwInterface *hw, CattaProtocol protocol);
163 void catta_interface_free(CattaInterface *i, int send_goodbye);
164
165 void catta_interface_update_rrs(CattaInterface *i, int remove_rrs);
166 void catta_interface_check_relevant(CattaInterface *i);
167 int catta_interface_is_relevant(CattaInterface *i);
168
169 void catta_interface_send_packet(CattaInterface *i, CattaDnsPacket *p);
170 void catta_interface_send_packet_unicast(CattaInterface *i, CattaDnsPacket *p, const CattaAddress *a, uint16_t port);
171
172 int catta_interface_post_query(CattaInterface *i, CattaKey *k, int immediately, unsigned *ret_id);
173 int catta_interface_withraw_query(CattaInterface *i, unsigned id);
174 int catta_interface_post_response(CattaInterface *i, CattaRecord *record, int flush_cache, const CattaAddress *querier, int immediately);
175 int catta_interface_post_probe(CattaInterface *i, CattaRecord *p, int immediately);
176
177 int catta_interface_match(CattaInterface *i, CattaIfIndex idx, CattaProtocol protocol);
178 int catta_interface_address_on_link(CattaInterface *i, const CattaAddress *a);
179 int catta_interface_has_address(CattaInterfaceMonitor *m, CattaIfIndex iface, const CattaAddress *a);
180
181 CattaInterface* catta_interface_monitor_get_interface(CattaInterfaceMonitor *m, CattaIfIndex idx, CattaProtocol protocol);
182
183 /* CattaInterfaceAddress */
184
185 CattaInterfaceAddress *catta_interface_address_new(CattaInterfaceMonitor *m, CattaInterface *i, const CattaAddress *addr, unsigned prefix_len);
186 void catta_interface_address_free(CattaInterfaceAddress *a);
187
188 void catta_interface_address_update_rrs(CattaInterfaceAddress *a, int remove_rrs);
189 int catta_interface_address_is_relevant(CattaInterfaceAddress *a);
190
191 CattaInterfaceAddress* catta_interface_monitor_get_address(CattaInterfaceMonitor *m, CattaInterface *i, const CattaAddress *raddr);
192
193 CattaIfIndex catta_find_interface_for_address(CattaInterfaceMonitor *m, const CattaAddress *a);
194
195 #endif