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