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 * 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 __DragonFly__ /* sigh */
45 #include <osreldate.h>
46 #define rtentry kernel_rtentry
47 #include <net/route.h>
50 #include <net/ip_mroute/ip_mroute.h>
56 typedef u_int u_int32
;
58 typedef void (*cfunc_t
)(void *);
59 typedef void (*ihfunc_t
)(int, fd_set
*);
66 #include "pathnames.h"
73 * Miscellaneous constants and macros.
78 #define EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
80 #define TIMER_INTERVAL ROUTE_MAX_REPORT_DELAY
82 #define PROTOCOL_VERSION 3 /* increment when packet format/content changes */
83 #define MROUTED_VERSION 9 /* not in DVMRP packets at all */
85 #define DVMRP_CONSTANT 0x000eff00 /* constant portion of 'group' field */
87 #define MROUTED_LEVEL (DVMRP_CONSTANT | PROTOCOL_VERSION)
88 /* for IGMP 'group' field of DVMRP messages */
90 #define LEAF_FLAGS (( vifs_with_neighbors == 1 ) ? 0x010000 : 0)
91 /* more for IGMP 'group' field of DVMRP messages */
93 #define DEL_RTE_GROUP 0
94 #define DEL_ALL_ROUTES 1
95 /* for Deleting kernel table entries */
97 #define JAN_1970 2208988800UL /* 1970 - 1900 in seconds */
100 #define BIT_ZERO(X) ((X) = 0)
101 #define BIT_SET(X,n) ((X) |= 1 << (n))
102 #define BIT_CLR(X,n) ((X) &= ~(1 << (n)))
103 #define BIT_TST(X,n) ((X) & 1 << (n))
107 #define bcopy(a, b, c) memcpy(b, a, c)
108 #define bzero(s, n) memset((s), 0, (n))
109 #define setlinebuf(s) setvbuf(s, NULL, _IOLBF, 0)
112 #if defined(_AIX) || (defined(BSD) && (BSD >= 199103))
117 * External declarations for global variables and functions.
119 #define RECV_BUF_SIZE 8192
120 extern char *recv_buf
;
121 extern char *send_buf
;
122 extern int igmp_socket
;
124 extern int rsrr_socket
;
126 extern u_int32 allhosts_group
;
127 extern u_int32 allrtrs_group
;
128 extern u_int32 dvmrp_group
;
129 extern u_int32 dvmrp_genid
;
131 #define IF_DEBUG(l) if (debug && debug & (l))
133 #define DEBUG_PKT 0x0001
134 #define DEBUG_PRUNE 0x0002
135 #define DEBUG_ROUTE 0x0004
136 #define DEBUG_PEER 0x0008
137 #define DEBUG_CACHE 0x0010
138 #define DEBUG_TIMEOUT 0x0020
139 #define DEBUG_IF 0x0040
140 #define DEBUG_MEMBER 0x0080
141 #define DEBUG_TRACE 0x0100
142 #define DEBUG_IGMP 0x0200
143 #define DEBUG_RTDETAIL 0x0400
144 #define DEBUG_KERN 0x0800
145 #define DEBUG_RSRR 0x1000
146 #define DEBUG_ICMP 0x2000
148 #define DEFAULT_DEBUG 0x02de /* default if "-d" given without value */
151 extern int did_final_init
;
153 extern int routes_changed
;
154 extern int delay_change_reports
;
155 extern unsigned nroutes
;
157 extern struct uvif uvifs
[MAXVIFS
];
158 extern vifi_t numvifs
;
159 extern int vifs_down
;
160 extern int udp_socket
;
161 extern int vifs_with_neighbors
;
168 #if !(defined(BSD) && (BSD >= 199103))
171 extern char * sys_errlist
[];
175 #define MRT_INIT DVMRP_INIT
176 #define MRT_DONE DVMRP_DONE
177 #define MRT_ADD_VIF DVMRP_ADD_VIF
178 #define MRT_DEL_VIF DVMRP_DEL_VIF
179 #define MRT_ADD_MFC DVMRP_ADD_MFC
180 #define MRT_DEL_MFC DVMRP_DEL_MFC
184 #define IGMP_PIM 0x14
187 #define IPPROTO_IPIP 4
191 * The original multicast releases defined
192 * IGMP_HOST_{MEMBERSHIP_QUERY,MEMBERSHIP_REPORT,NEW_MEMBERSHIP_REPORT
193 * ,LEAVE_MESSAGE}. Later releases removed the HOST and inserted
194 * the IGMP version number. NetBSD inserted the version number in
195 * a different way. mrouted uses the new names, so we #define them
196 * to the old ones if needed.
198 #if !defined(IGMP_MEMBERSHIP_QUERY) && defined(IGMP_HOST_MEMBERSHIP_QUERY)
199 #define IGMP_MEMBERSHIP_QUERY IGMP_HOST_MEMBERSHIP_QUERY
200 #define IGMP_V2_LEAVE_GROUP IGMP_HOST_LEAVE_MESSAGE
202 #ifndef IGMP_V1_MEMBERSHIP_REPORT
203 #ifdef IGMP_HOST_MEMBERSHIP_REPORT
204 #define IGMP_V1_MEMBERSHIP_REPORT IGMP_HOST_MEMBERSHIP_REPORT
205 #define IGMP_V2_MEMBERSHIP_REPORT IGMP_HOST_NEW_MEMBERSHIP_REPORT
207 #ifdef IGMP_v1_HOST_MEMBERSHIP_REPORT
208 #define IGMP_V1_MEMBERSHIP_REPORT IGMP_v1_HOST_MEMBERSHIP_REPORT
209 #define IGMP_V2_MEMBERSHIP_REPORT IGMP_v2_HOST_MEMBERSHIP_REPORT
214 * NetBSD also renamed the mtrace types.
216 #if !defined(IGMP_MTRACE_RESP) && defined(IGMP_MTRACE_REPLY)
217 #define IGMP_MTRACE_RESP IGMP_MTRACE_REPLY
218 #define IGMP_MTRACE IGMP_MTRACE_QUERY
222 extern char * scaletime(u_long
);
223 extern void dolog(int, int, char *, ...) __printflike(3, 4);
224 extern int register_input_handler(int, ihfunc_t
);
227 extern void init_igmp(void);
228 extern void accept_igmp(int);
229 extern void build_igmp(u_int32
, u_int32
, int, int, u_int32
,
231 extern void send_igmp(u_int32
, u_int32
, int, int, u_int32
,
233 extern char * igmp_packet_kind(u_int
, u_int
);
234 extern int igmp_debug_kind(u_int
, u_int
);
237 extern void init_icmp(void);
240 extern void init_ipip(void);
241 extern void init_ipip_on_vif(struct uvif
*);
242 extern void send_ipip(u_int32
, u_int32
, int, int, u_int32
,
246 extern void callout_init(void);
247 extern void free_all_callouts(void);
248 extern void age_callout_queue(int);
249 extern int timer_nextTimer(void);
250 extern int timer_setTimer(int, cfunc_t
, void *);
251 extern int timer_clearTimer(int);
252 extern int timer_leftTimer(int);
255 extern void init_routes(void);
256 extern void start_route_updates(void);
257 extern void update_route(u_int32
, u_int32
, u_int
, u_int32
,
258 vifi_t
, struct listaddr
*);
259 extern void age_routes(void);
260 extern void expire_all_routes(void);
261 extern void free_all_routes(void);
262 extern void accept_probe(u_int32
, u_int32
, char *, int,
264 extern void accept_report(u_int32
, u_int32
, char *, int,
266 extern struct rtentry
* determine_route(u_int32 src
);
267 extern void report(int, vifi_t
, u_int32
);
268 extern void report_to_all_neighbors(int);
269 extern int report_next_chunk(void);
270 extern void blaster_alloc(vifi_t
);
271 extern void add_vif_to_routes(vifi_t
);
272 extern void delete_vif_from_routes(vifi_t
);
273 extern void add_neighbor_to_routes(vifi_t
, int);
274 extern void delete_neighbor_from_routes(u_int32
,
276 extern void dump_routes(FILE *fp
);
279 extern void init_vifs(void);
280 extern void zero_vif(struct uvif
*, int);
281 extern void init_installvifs(void);
282 extern void check_vif_state(void);
283 extern void send_on_vif(struct uvif
*, u_int32
, int, int);
284 extern vifi_t
find_vif(u_int32
, u_int32
);
285 extern void age_vifs(void);
286 extern void dump_vifs(FILE *);
287 extern void stop_all_vifs(void);
288 extern struct listaddr
*neighbor_info(vifi_t
, u_int32
);
289 extern void accept_group_report(u_int32
, u_int32
,
291 extern void query_groups(void);
292 extern void probe_for_neighbors(void);
293 extern struct listaddr
*update_neighbor(vifi_t
, u_int32
, int, char *, int,
295 extern void accept_neighbor_request(u_int32
, u_int32
);
296 extern void accept_neighbor_request2(u_int32
, u_int32
);
297 extern void accept_info_request(u_int32
, u_int32
,
299 extern void accept_info_reply(u_int32
, u_int32
,
301 extern void accept_neighbors(u_int32
, u_int32
,
302 u_char
*, int, u_int32
);
303 extern void accept_neighbors2(u_int32
, u_int32
,
304 u_char
*, int, u_int32
);
305 extern void accept_leave_message(u_int32
, u_int32
,
307 extern void accept_membership_query(u_int32
, u_int32
,
311 extern void config_vifs_from_kernel(void);
314 extern void config_vifs_from_file(void);
317 extern int inet_valid_host(u_int32
);
318 extern int inet_valid_mask(u_int32
);
319 extern int inet_valid_subnet(u_int32
, u_int32
);
320 extern char * inet_fmt(u_int32
, char *);
321 extern char * inet_fmts(u_int32
, u_int32
, char *);
322 extern u_int32
inet_parse(char *, int);
323 extern int inet_cksum(u_short
*, u_int
);
326 extern unsigned kroutes
;
327 extern void determine_forwvifs(struct gtable
*);
328 extern void send_prune_or_graft(struct gtable
*);
329 extern void add_table_entry(u_int32
, u_int32
);
330 extern void del_table_entry(struct rtentry
*,
332 extern void update_table_entry(struct rtentry
*, u_int32
);
333 extern int find_src_grp(u_int32
, u_int32
, u_int32
);
334 extern void init_ktable(void);
335 extern void steal_sources(struct rtentry
*);
336 extern void reset_neighbor_state(vifi_t
, u_int32
);
337 extern int grplst_mem(vifi_t
, u_int32
);
338 extern void free_all_prunes(void);
339 extern void age_table_entry(void);
340 extern void dump_cache(FILE *);
341 extern void update_lclgrp(vifi_t
, u_int32
);
342 extern void delete_lclgrp(vifi_t
, u_int32
);
343 extern void chkgrp_graft(vifi_t
, u_int32
);
344 extern void accept_prune(u_int32
, u_int32
, char *, int);
345 extern void accept_graft(u_int32
, u_int32
, char *, int);
346 extern void accept_g_ack(u_int32
, u_int32
, char *, int);
347 /* u_int is promoted u_char */
348 extern void accept_mtrace(u_int32
, u_int32
,
349 u_int32
, char *, u_int
, int);
352 extern void k_set_rcvbuf(int, int);
353 extern void k_hdr_include(int);
354 extern void k_set_ttl(int);
355 extern void k_set_loop(int);
356 extern void k_set_if(u_int32
);
357 extern void k_join(u_int32
, u_int32
);
358 extern void k_leave(u_int32
, u_int32
);
359 extern void k_init_dvmrp(void);
360 extern void k_stop_dvmrp(void);
361 extern void k_add_vif(vifi_t
, struct uvif
*);
362 extern void k_del_vif(vifi_t
);
363 extern void k_add_rg(u_int32
, struct gtable
*);
364 extern int k_del_rg(u_int32
, struct gtable
*);
365 extern int k_get_version(void);
369 extern struct gtable
* find_grp(u_int32
);
370 extern struct stable
* find_grp_src(struct gtable
*, u_int32
);
371 extern int next_grp_src_mask(struct gtable
**,
372 struct stable
**, u_int32
,
374 extern void refresh_sg(struct sioc_sg_req
*, struct gtable
*,
376 extern int next_child(struct gtable
**, struct stable
**,
377 u_int32
, u_int32
, u_int32
,
381 extern struct rtentry
* snmp_find_route(u_int32
, u_int32
);
382 extern int next_route(struct rtentry
**, u_int32
, u_int32
);
383 extern int next_route_child(struct rtentry
**,
384 u_int32
, u_int32
, vifi_t
*);
389 extern struct gtable
*kernel_table
;
390 extern struct gtable
*gtp
;
393 extern void rsrr_init(void);
394 extern void rsrr_clean(void);
395 extern void rsrr_cache_send(struct gtable
*, int);
396 extern void rsrr_cache_clean(struct gtable
*);