5 This file is part of catta.
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.
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.
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
23 typedef struct CattaInterfaceMonitor CattaInterfaceMonitor;
24 typedef struct CattaInterfaceAddress CattaInterfaceAddress;
25 typedef struct CattaInterface CattaInterface;
26 typedef struct CattaHwInterface CattaHwInterface;
28 #include <catta/llist.h>
29 #include <catta/address.h>
33 #include "response-sched.h"
34 #include "query-sched.h"
35 #include "probe-sched.h"
42 #include "iface-linux.h"
43 #elif defined(HAVE_PF_ROUTE)
44 #include "iface-pfroute.h"
46 #include "iface-windows.h"
48 typedef struct CattaInterfaceMonitorOSDep CattaInterfaceMonitorOSDep;
49 struct CattaInterfaceMonitorOSDep {
51 unsigned query_addr_seq, query_link_seq;
61 #define CATTA_MAC_ADDRESS_MAX 32
63 struct CattaInterfaceMonitor {
65 CattaHashmap *hashmap;
67 CATTA_LLIST_HEAD(CattaInterface, interfaces);
68 CATTA_LLIST_HEAD(CattaHwInterface, hw_interfaces);
71 CattaInterfaceMonitorOSDep osdep;
74 struct CattaHwInterface {
75 CattaInterfaceMonitor *monitor;
77 CATTA_LLIST_FIELDS(CattaHwInterface, hardware);
85 uint8_t mac_address[CATTA_MAC_ADDRESS_MAX];
86 size_t mac_address_size;
88 CattaSEntryGroup *entry_group;
90 /* Packet rate limiting */
91 struct timeval ratelimit_begin;
92 unsigned ratelimit_counter;
94 CATTA_LLIST_HEAD(CattaInterface, interfaces);
97 struct CattaInterface {
98 CattaInterfaceMonitor *monitor;
99 CattaHwInterface *hardware;
101 CATTA_LLIST_FIELDS(CattaInterface, iface);
102 CATTA_LLIST_FIELDS(CattaInterface, by_hardware);
104 CattaProtocol protocol;
106 CattaAddress local_mcast_address;
111 CattaQueryScheduler *query_scheduler;
112 CattaResponseScheduler * response_scheduler;
113 CattaProbeScheduler *probe_scheduler;
115 CATTA_LLIST_HEAD(CattaInterfaceAddress, addresses);
116 CATTA_LLIST_HEAD(CattaAnnouncer, announcers);
118 CattaHashmap *queriers_by_key;
119 CATTA_LLIST_HEAD(CattaQuerier, queriers);
122 struct CattaInterfaceAddress {
123 CattaInterfaceMonitor *monitor;
124 CattaInterface *iface;
126 CATTA_LLIST_FIELDS(CattaInterfaceAddress, address);
128 CattaAddress address;
134 CattaSEntryGroup *entry_group;
137 CattaInterfaceMonitor *catta_interface_monitor_new(CattaServer *server);
138 void catta_interface_monitor_free(CattaInterfaceMonitor *m);
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);
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);
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);
152 /* CattaHwInterface */
154 CattaHwInterface *catta_hw_interface_new(CattaInterfaceMonitor *m, CattaIfIndex idx);
155 void catta_hw_interface_free(CattaHwInterface *hw, int send_goodbye);
157 void catta_hw_interface_update_rrs(CattaHwInterface *hw, int remove_rrs);
158 void catta_hw_interface_check_relevant(CattaHwInterface *hw);
160 CattaHwInterface* catta_interface_monitor_get_hw_interface(CattaInterfaceMonitor *m, CattaIfIndex idx);
164 CattaInterface* catta_interface_new(CattaInterfaceMonitor *m, CattaHwInterface *hw, CattaProtocol protocol);
165 void catta_interface_free(CattaInterface *i, int send_goodbye);
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);
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);
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);
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);
183 CattaInterface* catta_interface_monitor_get_interface(CattaInterfaceMonitor *m, CattaIfIndex idx, CattaProtocol protocol);
185 /* CattaInterfaceAddress */
187 CattaInterfaceAddress *catta_interface_address_new(CattaInterfaceMonitor *m, CattaInterface *i, const CattaAddress *addr, unsigned prefix_len);
188 void catta_interface_address_free(CattaInterfaceAddress *a);
190 void catta_interface_address_update_rrs(CattaInterfaceAddress *a, int remove_rrs);
191 int catta_interface_address_is_relevant(CattaInterfaceAddress *a);
193 CattaInterfaceAddress* catta_interface_monitor_get_address(CattaInterfaceMonitor *m, CattaInterface *i, const CattaAddress *raddr);
195 CattaIfIndex catta_find_interface_for_address(CattaInterfaceMonitor *m, const CattaAddress *a);