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.
11 * defs.h,v 3.8.4.15 1998/03/01 02:51:42 fenner Exp
23 #include <sys/param.h>
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <sys/ioctl.h>
28 #include <sys/sockio.h>
36 #define rtentry kern_rtentry /* XXX !!! UGH */
37 #include <net/route.h>
39 #include <netinet/in.h>
40 #include <netinet/in_systm.h>
41 #include <netinet/ip.h>
42 #include <netinet/ip_icmp.h>
43 #include <netinet/igmp.h>
44 #ifdef __FreeBSD__ /* sigh */
45 #include <osreldate.h>
46 #if __FreeBSD_version >= 220000
47 #define rtentry kernel_rtentry
48 #include <net/route.h>
52 #include <netinet/ip_mroute.h>
58 typedef u_int u_int32;
68 typedef void (*cfunc_t) __P((void *));
69 typedef void (*ihfunc_t) __P((int, fd_set *));
76 #include "pathnames.h"
83 * Miscellaneous constants and macros.
88 #define EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
90 #define TIMER_INTERVAL ROUTE_MAX_REPORT_DELAY
92 #define PROTOCOL_VERSION 3 /* increment when packet format/content changes */
93 #define MROUTED_VERSION 9 /* not in DVMRP packets at all */
95 #define DVMRP_CONSTANT 0x000eff00 /* constant portion of 'group' field */
97 #define MROUTED_LEVEL (DVMRP_CONSTANT | PROTOCOL_VERSION)
98 /* for IGMP 'group' field of DVMRP messages */
100 #define LEAF_FLAGS (( vifs_with_neighbors == 1 ) ? 0x010000 : 0)
101 /* more for IGMP 'group' field of DVMRP messages */
103 #define DEL_RTE_GROUP 0
104 #define DEL_ALL_ROUTES 1
105 /* for Deleting kernel table entries */
107 /* obnoxious gcc gives an extraneous warning about this constant... */
108 #if defined(__STDC__) || defined(__GNUC__)
109 #define JAN_1970 2208988800UL /* 1970 - 1900 in seconds */
111 #define JAN_1970 2208988800L /* 1970 - 1900 in seconds */
116 #define BIT_ZERO(X) ((X) = 0)
117 #define BIT_SET(X,n) ((X) |= 1 << (n))
118 #define BIT_CLR(X,n) ((X) &= ~(1 << (n)))
119 #define BIT_TST(X,n) ((X) & 1 << (n))
123 #define bcopy(a, b, c) memcpy(b, a, c)
124 #define bzero(s, n) memset((s), 0, (n))
125 #define setlinebuf(s) setvbuf(s, NULL, _IOLBF, 0)
128 #if defined(_AIX) || (defined(BSD) && (BSD >= 199103))
133 * External declarations for global variables and functions.
135 #define RECV_BUF_SIZE 8192
136 extern char *recv_buf;
137 extern char *send_buf;
138 extern int igmp_socket;
140 extern int rsrr_socket;
142 extern u_int32 allhosts_group;
143 extern u_int32 allrtrs_group;
144 extern u_int32 dvmrp_group;
145 extern u_int32 dvmrp_genid;
147 #define IF_DEBUG(l) if (debug && debug & (l))
149 #define DEBUG_PKT 0x0001
150 #define DEBUG_PRUNE 0x0002
151 #define DEBUG_ROUTE 0x0004
152 #define DEBUG_PEER 0x0008
153 #define DEBUG_CACHE 0x0010
154 #define DEBUG_TIMEOUT 0x0020
155 #define DEBUG_IF 0x0040
156 #define DEBUG_MEMBER 0x0080
157 #define DEBUG_TRACE 0x0100
158 #define DEBUG_IGMP 0x0200
159 #define DEBUG_RTDETAIL 0x0400
160 #define DEBUG_KERN 0x0800
161 #define DEBUG_RSRR 0x1000
162 #define DEBUG_ICMP 0x2000
164 #define DEFAULT_DEBUG 0x02de /* default if "-d" given without value */
167 extern int did_final_init;
169 extern int routes_changed;
170 extern int delay_change_reports;
171 extern unsigned nroutes;
173 extern struct uvif uvifs[MAXVIFS];
174 extern vifi_t numvifs;
175 extern int vifs_down;
176 extern int udp_socket;
177 extern int vifs_with_neighbors;
184 #if !(defined(BSD) && (BSD >= 199103))
187 extern char * sys_errlist[];
191 #define MRT_INIT DVMRP_INIT
192 #define MRT_DONE DVMRP_DONE
193 #define MRT_ADD_VIF DVMRP_ADD_VIF
194 #define MRT_DEL_VIF DVMRP_DEL_VIF
195 #define MRT_ADD_MFC DVMRP_ADD_MFC
196 #define MRT_DEL_MFC DVMRP_DEL_MFC
200 #define IGMP_PIM 0x14
203 #define IPPROTO_IPIP 4
207 * The original multicast releases defined
208 * IGMP_HOST_{MEMBERSHIP_QUERY,MEMBERSHIP_REPORT,NEW_MEMBERSHIP_REPORT
209 * ,LEAVE_MESSAGE}. Later releases removed the HOST and inserted
210 * the IGMP version number. NetBSD inserted the version number in
211 * a different way. mrouted uses the new names, so we #define them
212 * to the old ones if needed.
214 #if !defined(IGMP_MEMBERSHIP_QUERY) && defined(IGMP_HOST_MEMBERSHIP_QUERY)
215 #define IGMP_MEMBERSHIP_QUERY IGMP_HOST_MEMBERSHIP_QUERY
216 #define IGMP_V2_LEAVE_GROUP IGMP_HOST_LEAVE_MESSAGE
218 #ifndef IGMP_V1_MEMBERSHIP_REPORT
219 #ifdef IGMP_HOST_MEMBERSHIP_REPORT
220 #define IGMP_V1_MEMBERSHIP_REPORT IGMP_HOST_MEMBERSHIP_REPORT
221 #define IGMP_V2_MEMBERSHIP_REPORT IGMP_HOST_NEW_MEMBERSHIP_REPORT
223 #ifdef IGMP_v1_HOST_MEMBERSHIP_REPORT
224 #define IGMP_V1_MEMBERSHIP_REPORT IGMP_v1_HOST_MEMBERSHIP_REPORT
225 #define IGMP_V2_MEMBERSHIP_REPORT IGMP_v2_HOST_MEMBERSHIP_REPORT
230 * NetBSD also renamed the mtrace types.
232 #if !defined(IGMP_MTRACE_RESP) && defined(IGMP_MTRACE_REPLY)
233 #define IGMP_MTRACE_RESP IGMP_MTRACE_REPLY
234 #define IGMP_MTRACE IGMP_MTRACE_QUERY
238 extern char * scaletime __P((u_long));
239 extern void log __P((int, int, char *, ...)) __printflike(3, 4);
240 extern int register_input_handler __P((int, ihfunc_t));
243 extern void init_igmp __P((void));
244 extern void accept_igmp __P((int));
245 extern void build_igmp __P((u_int32, u_int32, int, int, u_int32,
247 extern void send_igmp __P((u_int32, u_int32, int, int, u_int32,
249 extern char * igmp_packet_kind __P((u_int, u_int));
250 extern int igmp_debug_kind __P((u_int, u_int));
253 extern void init_icmp __P((void));
256 extern void init_ipip __P((void));
257 extern void init_ipip_on_vif __P((struct uvif *));
258 extern void send_ipip __P((u_int32, u_int32, int, int, u_int32,
259 int, struct uvif *));
262 extern void callout_init __P((void));
263 extern void free_all_callouts __P((void));
264 extern void age_callout_queue __P((int));
265 extern int timer_nextTimer __P((void));
266 extern int timer_setTimer __P((int, cfunc_t, void *));
267 extern int timer_clearTimer __P((int));
268 extern int timer_leftTimer __P((int));
271 extern void init_routes __P((void));
272 extern void start_route_updates __P((void));
273 extern void update_route __P((u_int32, u_int32, u_int, u_int32,
274 vifi_t, struct listaddr *));
275 extern void age_routes __P((void));
276 extern void expire_all_routes __P((void));
277 extern void free_all_routes __P((void));
278 extern void accept_probe __P((u_int32, u_int32, char *, int,
280 extern void accept_report __P((u_int32, u_int32, char *, int,
282 extern struct rtentry * determine_route __P((u_int32 src));
283 extern void report __P((int, vifi_t, u_int32));
284 extern void report_to_all_neighbors __P((int));
285 extern int report_next_chunk __P((void));
286 extern void blaster_alloc __P((vifi_t));
287 extern void add_vif_to_routes __P((vifi_t));
288 extern void delete_vif_from_routes __P((vifi_t));
289 extern void add_neighbor_to_routes __P((vifi_t, int));
290 extern void delete_neighbor_from_routes __P((u_int32,
292 extern void dump_routes __P((FILE *fp));
295 extern void init_vifs __P((void));
296 extern void zero_vif __P((struct uvif *, int));
297 extern void init_installvifs __P((void));
298 extern void check_vif_state __P((void));
299 extern void send_on_vif __P((struct uvif *, u_int32, int, int));
300 extern vifi_t find_vif __P((u_int32, u_int32));
301 extern void age_vifs __P((void));
302 extern void dump_vifs __P((FILE *));
303 extern void stop_all_vifs __P((void));
304 extern struct listaddr *neighbor_info __P((vifi_t, u_int32));
305 extern void accept_group_report __P((u_int32, u_int32,
307 extern void query_groups __P((void));
308 extern void probe_for_neighbors __P((void));
309 extern struct listaddr *update_neighbor __P((vifi_t, u_int32, int, char *, int,
311 extern void accept_neighbor_request __P((u_int32, u_int32));
312 extern void accept_neighbor_request2 __P((u_int32, u_int32));
313 extern void accept_info_request __P((u_int32, u_int32,
315 extern void accept_info_reply __P((u_int32, u_int32,
317 extern void accept_neighbors __P((u_int32, u_int32,
318 u_char *, int, u_int32));
319 extern void accept_neighbors2 __P((u_int32, u_int32,
320 u_char *, int, u_int32));
321 extern void accept_leave_message __P((u_int32, u_int32,
323 extern void accept_membership_query __P((u_int32, u_int32,
327 extern void config_vifs_from_kernel __P((void));
330 extern void config_vifs_from_file __P((void));
333 extern int inet_valid_host __P((u_int32));
334 extern int inet_valid_mask __P((u_int32));
335 extern int inet_valid_subnet __P((u_int32, u_int32));
336 extern char * inet_fmt __P((u_int32, char *));
337 extern char * inet_fmts __P((u_int32, u_int32, char *));
338 extern u_int32 inet_parse __P((char *, int));
339 extern int inet_cksum __P((u_short *, u_int));
342 extern unsigned kroutes;
343 extern void determine_forwvifs __P((struct gtable *));
344 extern void send_prune_or_graft __P((struct gtable *));
345 extern void add_table_entry __P((u_int32, u_int32));
346 extern void del_table_entry __P((struct rtentry *,
348 extern void update_table_entry __P((struct rtentry *, u_int32));
349 extern int find_src_grp __P((u_int32, u_int32, u_int32));
350 extern void init_ktable __P((void));
351 extern void steal_sources __P((struct rtentry *));
352 extern void reset_neighbor_state __P((vifi_t, u_int32));
353 extern int grplst_mem __P((vifi_t, u_int32));
354 extern void free_all_prunes __P((void));
355 extern void age_table_entry __P((void));
356 extern void dump_cache __P((FILE *));
357 extern void update_lclgrp __P((vifi_t, u_int32));
358 extern void delete_lclgrp __P((vifi_t, u_int32));
359 extern void chkgrp_graft __P((vifi_t, u_int32));
360 extern void accept_prune __P((u_int32, u_int32, char *, int));
361 extern void accept_graft __P((u_int32, u_int32, char *, int));
362 extern void accept_g_ack __P((u_int32, u_int32, char *, int));
363 /* u_int is promoted u_char */
364 extern void accept_mtrace __P((u_int32, u_int32,
365 u_int32, char *, u_int, int));
368 extern void k_set_rcvbuf __P((int, int));
369 extern void k_hdr_include __P((int));
370 extern void k_set_ttl __P((int));
371 extern void k_set_loop __P((int));
372 extern void k_set_if __P((u_int32));
373 extern void k_join __P((u_int32, u_int32));
374 extern void k_leave __P((u_int32, u_int32));
375 extern void k_init_dvmrp __P((void));
376 extern void k_stop_dvmrp __P((void));
377 extern void k_add_vif __P((vifi_t, struct uvif *));
378 extern void k_del_vif __P((vifi_t));
379 extern void k_add_rg __P((u_int32, struct gtable *));
380 extern int k_del_rg __P((u_int32, struct gtable *));
381 extern int k_get_version __P((void));
385 extern struct gtable * find_grp __P((u_int32));
386 extern struct stable * find_grp_src __P((struct gtable *, u_int32));
387 extern int next_grp_src_mask __P((struct gtable **,
388 struct stable **, u_int32,
390 extern void refresh_sg __P((struct sioc_sg_req *, struct gtable *,
392 extern int next_child __P((struct gtable **, struct stable **,
393 u_int32, u_int32, u_int32,
397 extern struct rtentry * snmp_find_route __P((u_int32, u_int32));
398 extern int next_route __P((struct rtentry **, u_int32, u_int32));
399 extern int next_route_child __P((struct rtentry **,
400 u_int32, u_int32, vifi_t *));
405 extern struct gtable *kernel_table;
406 extern struct gtable *gtp;
409 extern void rsrr_init __P((void));
410 extern void rsrr_clean __P((void));
411 extern void rsrr_cache_send __P((struct gtable *, int));
412 extern void rsrr_cache_clean __P((struct gtable *));