Sync with NetBSD. Many fixes to include:
[dragonfly.git] / usr.sbin / mrouted / defs.h
blob7a078e1840fa521f13ec9ed61ca42d6ed8102e05
1 /*
2 * The mrouted program is covered by the license in the accompanying file
3 * named "LICENSE". Use of the mrouted program represents acceptance of
4 * the terms and conditions listed in that file.
6 * The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
7 * Leland Stanford Junior University.
10 * $FreeBSD: src/usr.sbin/mrouted/defs.h,v 1.12.2.1 2001/07/19 01:41:11 kris Exp $
11 * $DragonFly: src/usr.sbin/mrouted/defs.h,v 1.6 2004/02/10 02:59:42 rob Exp $
12 * defs.h,v 3.8.4.15 1998/03/01 02:51:42 fenner Exp
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19 #include <ctype.h>
20 #include <errno.h>
21 #include <syslog.h>
22 #include <signal.h>
23 #include <string.h>
24 #include <sys/param.h>
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <sys/ioctl.h>
28 #ifdef SYSV
29 #include <sys/sockio.h>
30 #endif
31 #ifdef _AIX
32 #include <time.h>
33 #endif
34 #include <sys/time.h>
35 #include <sys/uio.h>
36 #include <net/if.h>
37 #define rtentry kern_rtentry /* XXX !!! UGH */
38 #include <net/route.h>
39 #undef rtentry
40 #include <netinet/in.h>
41 #include <netinet/in_systm.h>
42 #include <netinet/ip.h>
43 #include <netinet/ip_icmp.h>
44 #include <netinet/igmp.h>
45 #ifdef __DragonFly__ /* sigh */
46 #include <osreldate.h>
47 #define rtentry kernel_rtentry
48 #include <net/route.h>
49 #undef rtentry
50 #endif
51 #include <net/ip_mroute/ip_mroute.h>
52 #ifdef RSRR
53 #include <sys/un.h>
54 #endif /* RSRR */
56 /*XXX*/
57 typedef u_int u_int32;
59 typedef void (*cfunc_t)(void *);
60 typedef void (*ihfunc_t)(int, fd_set *);
62 #include "dvmrp.h"
63 #include "igmpv2.h"
64 #include "vif.h"
65 #include "route.h"
66 #include "prune.h"
67 #include "pathnames.h"
68 #ifdef RSRR
69 #include "rsrr.h"
70 #include "rsrr_var.h"
71 #endif /* RSRR */
74 * Miscellaneous constants and macros.
76 #define FALSE 0
77 #define TRUE 1
79 #define EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
81 #define TIMER_INTERVAL ROUTE_MAX_REPORT_DELAY
83 #define PROTOCOL_VERSION 3 /* increment when packet format/content changes */
84 #define MROUTED_VERSION 9 /* not in DVMRP packets at all */
86 #define DVMRP_CONSTANT 0x000eff00 /* constant portion of 'group' field */
88 #define MROUTED_LEVEL (DVMRP_CONSTANT | PROTOCOL_VERSION)
89 /* for IGMP 'group' field of DVMRP messages */
91 #define LEAF_FLAGS (( vifs_with_neighbors == 1 ) ? 0x010000 : 0)
92 /* more for IGMP 'group' field of DVMRP messages */
94 #define DEL_RTE_GROUP 0
95 #define DEL_ALL_ROUTES 1
96 /* for Deleting kernel table entries */
98 /* obnoxious gcc gives an extraneous warning about this constant... */
99 #if defined(__STDC__) || defined(__GNUC__)
100 #define JAN_1970 2208988800UL /* 1970 - 1900 in seconds */
101 #else
102 #define JAN_1970 2208988800L /* 1970 - 1900 in seconds */
103 #define const /**/
104 #endif
106 #ifdef RSRR
107 #define BIT_ZERO(X) ((X) = 0)
108 #define BIT_SET(X,n) ((X) |= 1 << (n))
109 #define BIT_CLR(X,n) ((X) &= ~(1 << (n)))
110 #define BIT_TST(X,n) ((X) & 1 << (n))
111 #endif /* RSRR */
113 #ifdef SYSV
114 #define bcopy(a, b, c) memcpy(b, a, c)
115 #define bzero(s, n) memset((s), 0, (n))
116 #define setlinebuf(s) setvbuf(s, NULL, _IOLBF, 0)
117 #endif
119 #if defined(_AIX) || (defined(BSD) && (BSD >= 199103))
120 #define HAVE_SA_LEN
121 #endif
124 * External declarations for global variables and functions.
126 #define RECV_BUF_SIZE 8192
127 extern char *recv_buf;
128 extern char *send_buf;
129 extern int igmp_socket;
130 #ifdef RSRR
131 extern int rsrr_socket;
132 #endif /* RSRR */
133 extern u_int32 allhosts_group;
134 extern u_int32 allrtrs_group;
135 extern u_int32 dvmrp_group;
136 extern u_int32 dvmrp_genid;
138 #define IF_DEBUG(l) if (debug && debug & (l))
140 #define DEBUG_PKT 0x0001
141 #define DEBUG_PRUNE 0x0002
142 #define DEBUG_ROUTE 0x0004
143 #define DEBUG_PEER 0x0008
144 #define DEBUG_CACHE 0x0010
145 #define DEBUG_TIMEOUT 0x0020
146 #define DEBUG_IF 0x0040
147 #define DEBUG_MEMBER 0x0080
148 #define DEBUG_TRACE 0x0100
149 #define DEBUG_IGMP 0x0200
150 #define DEBUG_RTDETAIL 0x0400
151 #define DEBUG_KERN 0x0800
152 #define DEBUG_RSRR 0x1000
153 #define DEBUG_ICMP 0x2000
155 #define DEFAULT_DEBUG 0x02de /* default if "-d" given without value */
157 extern int debug;
158 extern int did_final_init;
160 extern int routes_changed;
161 extern int delay_change_reports;
162 extern unsigned nroutes;
164 extern struct uvif uvifs[MAXVIFS];
165 extern vifi_t numvifs;
166 extern int vifs_down;
167 extern int udp_socket;
168 extern int vifs_with_neighbors;
170 extern char s1[];
171 extern char s2[];
172 extern char s3[];
173 extern char s4[];
175 #if !(defined(BSD) && (BSD >= 199103))
176 extern int errno;
177 extern int sys_nerr;
178 extern char * sys_errlist[];
179 #endif
181 #ifdef OLD_KERNEL
182 #define MRT_INIT DVMRP_INIT
183 #define MRT_DONE DVMRP_DONE
184 #define MRT_ADD_VIF DVMRP_ADD_VIF
185 #define MRT_DEL_VIF DVMRP_DEL_VIF
186 #define MRT_ADD_MFC DVMRP_ADD_MFC
187 #define MRT_DEL_MFC DVMRP_DEL_MFC
188 #endif
190 #ifndef IGMP_PIM
191 #define IGMP_PIM 0x14
192 #endif
193 #ifndef IPPROTO_IPIP
194 #define IPPROTO_IPIP 4
195 #endif
198 * The original multicast releases defined
199 * IGMP_HOST_{MEMBERSHIP_QUERY,MEMBERSHIP_REPORT,NEW_MEMBERSHIP_REPORT
200 * ,LEAVE_MESSAGE}. Later releases removed the HOST and inserted
201 * the IGMP version number. NetBSD inserted the version number in
202 * a different way. mrouted uses the new names, so we #define them
203 * to the old ones if needed.
205 #if !defined(IGMP_MEMBERSHIP_QUERY) && defined(IGMP_HOST_MEMBERSHIP_QUERY)
206 #define IGMP_MEMBERSHIP_QUERY IGMP_HOST_MEMBERSHIP_QUERY
207 #define IGMP_V2_LEAVE_GROUP IGMP_HOST_LEAVE_MESSAGE
208 #endif
209 #ifndef IGMP_V1_MEMBERSHIP_REPORT
210 #ifdef IGMP_HOST_MEMBERSHIP_REPORT
211 #define IGMP_V1_MEMBERSHIP_REPORT IGMP_HOST_MEMBERSHIP_REPORT
212 #define IGMP_V2_MEMBERSHIP_REPORT IGMP_HOST_NEW_MEMBERSHIP_REPORT
213 #endif
214 #ifdef IGMP_v1_HOST_MEMBERSHIP_REPORT
215 #define IGMP_V1_MEMBERSHIP_REPORT IGMP_v1_HOST_MEMBERSHIP_REPORT
216 #define IGMP_V2_MEMBERSHIP_REPORT IGMP_v2_HOST_MEMBERSHIP_REPORT
217 #endif
218 #endif
221 * NetBSD also renamed the mtrace types.
223 #if !defined(IGMP_MTRACE_RESP) && defined(IGMP_MTRACE_REPLY)
224 #define IGMP_MTRACE_RESP IGMP_MTRACE_REPLY
225 #define IGMP_MTRACE IGMP_MTRACE_QUERY
226 #endif
228 /* main.c */
229 extern char * scaletime(u_long);
230 extern void log(int, int, char *, ...) __printflike(3, 4);
231 extern int register_input_handler(int, ihfunc_t);
233 /* igmp.c */
234 extern void init_igmp(void);
235 extern void accept_igmp(int);
236 extern void build_igmp(u_int32, u_int32, int, int, u_int32,
237 int);
238 extern void send_igmp(u_int32, u_int32, int, int, u_int32,
239 int);
240 extern char * igmp_packet_kind(u_int, u_int);
241 extern int igmp_debug_kind(u_int, u_int);
243 /* icmp.c */
244 extern void init_icmp(void);
246 /* ipip.c */
247 extern void init_ipip(void);
248 extern void init_ipip_on_vif(struct uvif *);
249 extern void send_ipip(u_int32, u_int32, int, int, u_int32,
250 int, struct uvif *);
252 /* callout.c */
253 extern void callout_init(void);
254 extern void free_all_callouts(void);
255 extern void age_callout_queue(int);
256 extern int timer_nextTimer(void);
257 extern int timer_setTimer(int, cfunc_t, void *);
258 extern int timer_clearTimer(int);
259 extern int timer_leftTimer(int);
261 /* route.c */
262 extern void init_routes(void);
263 extern void start_route_updates(void);
264 extern void update_route(u_int32, u_int32, u_int, u_int32,
265 vifi_t, struct listaddr *);
266 extern void age_routes(void);
267 extern void expire_all_routes(void);
268 extern void free_all_routes(void);
269 extern void accept_probe(u_int32, u_int32, char *, int,
270 u_int32);
271 extern void accept_report(u_int32, u_int32, char *, int,
272 u_int32);
273 extern struct rtentry * determine_route(u_int32 src);
274 extern void report(int, vifi_t, u_int32);
275 extern void report_to_all_neighbors(int);
276 extern int report_next_chunk(void);
277 extern void blaster_alloc(vifi_t);
278 extern void add_vif_to_routes(vifi_t);
279 extern void delete_vif_from_routes(vifi_t);
280 extern void add_neighbor_to_routes(vifi_t, int);
281 extern void delete_neighbor_from_routes(u_int32,
282 vifi_t, int);
283 extern void dump_routes(FILE *fp);
285 /* vif.c */
286 extern void init_vifs(void);
287 extern void zero_vif(struct uvif *, int);
288 extern void init_installvifs(void);
289 extern void check_vif_state(void);
290 extern void send_on_vif(struct uvif *, u_int32, int, int);
291 extern vifi_t find_vif(u_int32, u_int32);
292 extern void age_vifs(void);
293 extern void dump_vifs(FILE *);
294 extern void stop_all_vifs(void);
295 extern struct listaddr *neighbor_info(vifi_t, u_int32);
296 extern void accept_group_report(u_int32, u_int32,
297 u_int32, int);
298 extern void query_groups(void);
299 extern void probe_for_neighbors(void);
300 extern struct listaddr *update_neighbor(vifi_t, u_int32, int, char *, int,
301 u_int32);
302 extern void accept_neighbor_request(u_int32, u_int32);
303 extern void accept_neighbor_request2(u_int32, u_int32);
304 extern void accept_info_request(u_int32, u_int32,
305 u_char *, int);
306 extern void accept_info_reply(u_int32, u_int32,
307 u_char *, int);
308 extern void accept_neighbors(u_int32, u_int32,
309 u_char *, int, u_int32);
310 extern void accept_neighbors2(u_int32, u_int32,
311 u_char *, int, u_int32);
312 extern void accept_leave_message(u_int32, u_int32,
313 u_int32);
314 extern void accept_membership_query(u_int32, u_int32,
315 u_int32, int);
317 /* config.c */
318 extern void config_vifs_from_kernel(void);
320 /* cfparse.y */
321 extern void config_vifs_from_file(void);
323 /* inet.c */
324 extern int inet_valid_host(u_int32);
325 extern int inet_valid_mask(u_int32);
326 extern int inet_valid_subnet(u_int32, u_int32);
327 extern char * inet_fmt(u_int32, char *);
328 extern char * inet_fmts(u_int32, u_int32, char *);
329 extern u_int32 inet_parse(char *, int);
330 extern int inet_cksum(u_short *, u_int);
332 /* prune.c */
333 extern unsigned kroutes;
334 extern void determine_forwvifs(struct gtable *);
335 extern void send_prune_or_graft(struct gtable *);
336 extern void add_table_entry(u_int32, u_int32);
337 extern void del_table_entry(struct rtentry *,
338 u_int32, u_int);
339 extern void update_table_entry(struct rtentry *, u_int32);
340 extern int find_src_grp(u_int32, u_int32, u_int32);
341 extern void init_ktable(void);
342 extern void steal_sources(struct rtentry *);
343 extern void reset_neighbor_state(vifi_t, u_int32);
344 extern int grplst_mem(vifi_t, u_int32);
345 extern void free_all_prunes(void);
346 extern void age_table_entry(void);
347 extern void dump_cache(FILE *);
348 extern void update_lclgrp(vifi_t, u_int32);
349 extern void delete_lclgrp(vifi_t, u_int32);
350 extern void chkgrp_graft(vifi_t, u_int32);
351 extern void accept_prune(u_int32, u_int32, char *, int);
352 extern void accept_graft(u_int32, u_int32, char *, int);
353 extern void accept_g_ack(u_int32, u_int32, char *, int);
354 /* u_int is promoted u_char */
355 extern void accept_mtrace(u_int32, u_int32,
356 u_int32, char *, u_int, int);
358 /* kern.c */
359 extern void k_set_rcvbuf(int, int);
360 extern void k_hdr_include(int);
361 extern void k_set_ttl(int);
362 extern void k_set_loop(int);
363 extern void k_set_if(u_int32);
364 extern void k_join(u_int32, u_int32);
365 extern void k_leave(u_int32, u_int32);
366 extern void k_init_dvmrp(void);
367 extern void k_stop_dvmrp(void);
368 extern void k_add_vif(vifi_t, struct uvif *);
369 extern void k_del_vif(vifi_t);
370 extern void k_add_rg(u_int32, struct gtable *);
371 extern int k_del_rg(u_int32, struct gtable *);
372 extern int k_get_version(void);
374 #ifdef SNMP
375 /* prune.c */
376 extern struct gtable * find_grp(u_int32);
377 extern struct stable * find_grp_src(struct gtable *, u_int32);
378 extern int next_grp_src_mask(struct gtable **,
379 struct stable **, u_int32,
380 u_int32, u_int32);
381 extern void refresh_sg(struct sioc_sg_req *, struct gtable *,
382 struct stable *);
383 extern int next_child(struct gtable **, struct stable **,
384 u_int32, u_int32, u_int32,
385 vifi_t *);
387 /* route.c */
388 extern struct rtentry * snmp_find_route(u_int32, u_int32);
389 extern int next_route(struct rtentry **, u_int32, u_int32);
390 extern int next_route_child(struct rtentry **,
391 u_int32, u_int32, vifi_t *);
392 #endif
394 #ifdef RSRR
395 /* prune.c */
396 extern struct gtable *kernel_table;
397 extern struct gtable *gtp;
399 /* rsrr.c */
400 extern void rsrr_init(void);
401 extern void rsrr_clean(void);
402 extern void rsrr_cache_send(struct gtable *, int);
403 extern void rsrr_cache_clean(struct gtable *);
404 #endif /* RSRR */