defs.h revision 1.7 1 1.7 lukem /* $NetBSD: defs.h,v 1.7 1997/10/17 10:38:03 lukem Exp $ */
2 1.5 thorpej
3 1.1 brezak /*
4 1.1 brezak * The mrouted program is covered by the license in the accompanying file
5 1.1 brezak * named "LICENSE". Use of the mrouted program represents acceptance of
6 1.1 brezak * the terms and conditions listed in that file.
7 1.1 brezak *
8 1.1 brezak * The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
9 1.1 brezak * Leland Stanford Junior University.
10 1.1 brezak */
11 1.1 brezak
12 1.1 brezak
13 1.6 mycroft #include <stdio.h>
14 1.6 mycroft #include <stdlib.h>
15 1.6 mycroft #include <unistd.h>
16 1.6 mycroft #include <ctype.h>
17 1.6 mycroft #include <errno.h>
18 1.6 mycroft #include <syslog.h>
19 1.6 mycroft #include <signal.h>
20 1.6 mycroft #include <string.h>
21 1.1 brezak #include <sys/param.h>
22 1.4 mycroft #include <sys/types.h>
23 1.1 brezak #include <sys/socket.h>
24 1.1 brezak #include <sys/ioctl.h>
25 1.6 mycroft #ifdef SYSV
26 1.6 mycroft #include <sys/sockio.h>
27 1.6 mycroft #endif
28 1.4 mycroft #include <sys/time.h>
29 1.1 brezak #include <net/if.h>
30 1.1 brezak #include <netinet/in.h>
31 1.1 brezak #include <netinet/in_systm.h>
32 1.1 brezak #include <netinet/ip.h>
33 1.1 brezak #include <netinet/igmp.h>
34 1.1 brezak #include <netinet/ip_mroute.h>
35 1.4 mycroft #ifdef RSRR
36 1.4 mycroft #include <sys/un.h>
37 1.4 mycroft #endif /* RSRR */
38 1.1 brezak
39 1.6 mycroft #ifndef __P
40 1.6 mycroft #ifdef __STDC__
41 1.6 mycroft #define __P(x) x
42 1.6 mycroft #else
43 1.6 mycroft #define __P(x) ()
44 1.6 mycroft #endif
45 1.6 mycroft #endif
46 1.6 mycroft
47 1.6 mycroft typedef void (*cfunc_t) __P((void *));
48 1.6 mycroft typedef void (*ihfunc_t) __P((int, fd_set *));
49 1.6 mycroft
50 1.1 brezak #include "dvmrp.h"
51 1.1 brezak #include "vif.h"
52 1.1 brezak #include "route.h"
53 1.4 mycroft #include "prune.h"
54 1.1 brezak #include "pathnames.h"
55 1.4 mycroft #ifdef RSRR
56 1.4 mycroft #include "rsrr.h"
57 1.6 mycroft #include "rsrr_var.h"
58 1.4 mycroft #endif /* RSRR */
59 1.1 brezak
60 1.1 brezak /*
61 1.1 brezak * Miscellaneous constants and macros.
62 1.1 brezak */
63 1.1 brezak #define FALSE 0
64 1.1 brezak #define TRUE 1
65 1.1 brezak
66 1.1 brezak #define EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
67 1.1 brezak
68 1.1 brezak #define TIMER_INTERVAL ROUTE_MAX_REPORT_DELAY
69 1.1 brezak
70 1.6 mycroft #define VENDOR_CODE 1 /* Get a new vendor code if you make significant
71 1.6 mycroft * changes to mrouted. */
72 1.6 mycroft
73 1.4 mycroft #define PROTOCOL_VERSION 3 /* increment when packet format/content changes */
74 1.1 brezak
75 1.6 mycroft #define MROUTED_VERSION 8 /* increment on local changes or bug fixes, */
76 1.1 brezak /* reset to 0 whever PROTOCOL_VERSION increments */
77 1.1 brezak
78 1.6 mycroft #define MROUTED_LEVEL ((MROUTED_VERSION << 8) | PROTOCOL_VERSION | \
79 1.6 mycroft ((NF_PRUNE | NF_GENID | NF_MTRACE) << 16) | \
80 1.6 mycroft (VENDOR_CODE << 24))
81 1.1 brezak /* for IGMP 'group' field of DVMRP messages */
82 1.1 brezak
83 1.4 mycroft #define LEAF_FLAGS (( vifs_with_neighbors == 1 ) ? 0x010000 : 0)
84 1.4 mycroft /* more for IGMP 'group' field of DVMRP messages */
85 1.4 mycroft #define DEL_RTE_GROUP 0
86 1.4 mycroft #define DEL_ALL_ROUTES 1
87 1.4 mycroft /* for Deleting kernel table entries */
88 1.4 mycroft
89 1.4 mycroft /* obnoxious gcc gives an extraneous warning about this constant... */
90 1.4 mycroft #if defined(__STDC__) || defined(__GNUC__)
91 1.4 mycroft #define JAN_1970 2208988800UL /* 1970 - 1900 in seconds */
92 1.4 mycroft #else
93 1.4 mycroft #define JAN_1970 2208988800L /* 1970 - 1900 in seconds */
94 1.6 mycroft #define const /**/
95 1.4 mycroft #endif
96 1.4 mycroft
97 1.4 mycroft #ifdef RSRR
98 1.4 mycroft #define BIT_ZERO(X) ((X) = 0)
99 1.4 mycroft #define BIT_SET(X,n) ((X) |= 1 << (n))
100 1.4 mycroft #define BIT_CLR(X,n) ((X) &= ~(1 << (n)))
101 1.4 mycroft #define BIT_TST(X,n) ((X) & 1 << (n))
102 1.4 mycroft #endif /* RSRR */
103 1.4 mycroft
104 1.6 mycroft #ifdef SYSV
105 1.6 mycroft #define bcopy(a, b, c) memcpy(b, a, c)
106 1.6 mycroft #define bzero(s, n) memset((s), 0, (n))
107 1.6 mycroft #define setlinebuf(s) setvbuf(s, NULL, _IOLBF, 0)
108 1.6 mycroft #define signal(s,f) sigset(s,f)
109 1.6 mycroft #endif
110 1.6 mycroft
111 1.1 brezak /*
112 1.1 brezak * External declarations for global variables and functions.
113 1.1 brezak */
114 1.6 mycroft #define RECV_BUF_SIZE 8192
115 1.4 mycroft extern char *recv_buf;
116 1.4 mycroft extern char *send_buf;
117 1.1 brezak extern int igmp_socket;
118 1.4 mycroft #ifdef RSRR
119 1.4 mycroft extern int rsrr_socket;
120 1.4 mycroft #endif /* RSRR */
121 1.4 mycroft extern u_int32_t allhosts_group;
122 1.4 mycroft extern u_int32_t allrtrs_group;
123 1.4 mycroft extern u_int32_t dvmrp_group;
124 1.4 mycroft extern u_int32_t dvmrp_genid;
125 1.1 brezak
126 1.1 brezak #define DEFAULT_DEBUG 2 /* default if "-d" given without value */
127 1.1 brezak
128 1.1 brezak extern int debug;
129 1.4 mycroft extern u_char pruning;
130 1.1 brezak
131 1.1 brezak extern int routes_changed;
132 1.1 brezak extern int delay_change_reports;
133 1.2 brezak extern unsigned nroutes;
134 1.1 brezak
135 1.1 brezak extern struct uvif uvifs[MAXVIFS];
136 1.1 brezak extern vifi_t numvifs;
137 1.1 brezak extern int vifs_down;
138 1.1 brezak extern int udp_socket;
139 1.4 mycroft extern int vifs_with_neighbors;
140 1.1 brezak
141 1.1 brezak extern char s1[];
142 1.1 brezak extern char s2[];
143 1.1 brezak extern char s3[];
144 1.4 mycroft extern char s4[];
145 1.1 brezak
146 1.6 mycroft #if !(defined(BSD) && (BSD >= 199103))
147 1.6 mycroft extern int errno;
148 1.6 mycroft extern int sys_nerr;
149 1.6 mycroft extern char * sys_errlist[];
150 1.6 mycroft #endif
151 1.1 brezak
152 1.6 mycroft #ifdef OLD_KERNEL
153 1.6 mycroft #define MRT_INIT DVMRP_INIT
154 1.6 mycroft #define MRT_DONE DVMRP_DONE
155 1.6 mycroft #define MRT_ADD_VIF DVMRP_ADD_VIF
156 1.6 mycroft #define MRT_DEL_VIF DVMRP_DEL_VIF
157 1.6 mycroft #define MRT_ADD_MFC DVMRP_ADD_MFC
158 1.6 mycroft #define MRT_DEL_MFC DVMRP_DEL_MFC
159 1.4 mycroft
160 1.6 mycroft #define IGMP_PIM 0x14
161 1.6 mycroft #endif
162 1.6 mycroft
163 1.6 mycroft /* main.c */
164 1.6 mycroft extern void log __P((int, int, char *, ...));
165 1.6 mycroft extern int register_input_handler __P((int fd, ihfunc_t func));
166 1.6 mycroft
167 1.6 mycroft /* igmp.c */
168 1.6 mycroft extern void init_igmp __P((void));
169 1.6 mycroft extern void accept_igmp __P((int recvlen));
170 1.6 mycroft extern void send_igmp __P((u_int32_t src, u_int32_t dst, int type,
171 1.6 mycroft int code, u_int32_t group,
172 1.6 mycroft int datalen));
173 1.6 mycroft
174 1.6 mycroft /* callout.c */
175 1.6 mycroft extern void callout_init __P((void));
176 1.6 mycroft extern void age_callout_queue __P((void));
177 1.6 mycroft extern int timer_setTimer __P((int delay, cfunc_t action,
178 1.6 mycroft char *data));
179 1.6 mycroft extern void timer_clearTimer __P((int timer_id));
180 1.6 mycroft
181 1.6 mycroft /* route.c */
182 1.6 mycroft extern void init_routes __P((void));
183 1.6 mycroft extern void start_route_updates __P((void));
184 1.6 mycroft extern void update_route __P((u_int32_t origin, u_int32_t mask,
185 1.6 mycroft u_int metric, u_int32_t src,
186 1.6 mycroft vifi_t vifi));
187 1.6 mycroft extern void age_routes __P((void));
188 1.6 mycroft extern void expire_all_routes __P((void));
189 1.6 mycroft extern void free_all_routes __P((void));
190 1.6 mycroft extern void accept_probe __P((u_int32_t src, u_int32_t dst,
191 1.6 mycroft char *p, int datalen,
192 1.6 mycroft u_int32_t level));
193 1.6 mycroft extern void accept_report __P((u_int32_t src, u_int32_t dst,
194 1.6 mycroft char *p, int datalen,
195 1.6 mycroft u_int32_t level));
196 1.6 mycroft extern struct rtentry * determine_route __P((u_int32_t src));
197 1.6 mycroft extern void report __P((int which_routes, vifi_t vifi,
198 1.6 mycroft u_int32_t dst));
199 1.6 mycroft extern void report_to_all_neighbors __P((int which_routes));
200 1.6 mycroft extern int report_next_chunk __P((void));
201 1.6 mycroft extern void add_vif_to_routes __P((vifi_t vifi));
202 1.6 mycroft extern void delete_vif_from_routes __P((vifi_t vifi));
203 1.6 mycroft extern void delete_neighbor_from_routes __P((u_int32_t addr,
204 1.6 mycroft vifi_t vifi));
205 1.6 mycroft extern void dump_routes __P((FILE *fp));
206 1.6 mycroft extern void start_route_updates __P((void));
207 1.6 mycroft
208 1.6 mycroft /* vif.c */
209 1.6 mycroft extern void init_vifs __P((void));
210 1.6 mycroft extern void check_vif_state __P((void));
211 1.6 mycroft extern vifi_t find_vif __P((u_int32_t src, u_int32_t dst));
212 1.6 mycroft extern void age_vifs __P((void));
213 1.6 mycroft extern void dump_vifs __P((FILE *fp));
214 1.6 mycroft extern void stop_all_vifs __P((void));
215 1.6 mycroft extern struct listaddr *neighbor_info __P((vifi_t vifi, u_int32_t addr));
216 1.6 mycroft extern void accept_group_report __P((u_int32_t src, u_int32_t dst,
217 1.6 mycroft u_int32_t group, int r_type));
218 1.6 mycroft extern void query_groups __P((void));
219 1.6 mycroft extern void probe_for_neighbors __P((void));
220 1.6 mycroft extern int update_neighbor __P((vifi_t vifi, u_int32_t addr,
221 1.6 mycroft int msgtype, char *p, int datalen,
222 1.6 mycroft u_int32_t level));
223 1.6 mycroft extern void accept_neighbor_request __P((u_int32_t src, u_int32_t dst));
224 1.6 mycroft extern void accept_neighbor_request2 __P((u_int32_t src,
225 1.6 mycroft u_int32_t dst));
226 1.6 mycroft extern void accept_neighbors __P((u_int32_t src, u_int32_t dst,
227 1.6 mycroft u_char *p, int datalen, u_int32_t level));
228 1.6 mycroft extern void accept_neighbors2 __P((u_int32_t src, u_int32_t dst,
229 1.6 mycroft u_char *p, int datalen, u_int32_t level));
230 1.6 mycroft extern void accept_leave_message __P((u_int32_t src, u_int32_t dst,
231 1.6 mycroft u_int32_t group));
232 1.6 mycroft extern void accept_membership_query __P((u_int32_t src, u_int32_t dst,
233 1.6 mycroft u_int32_t group, int tmo));
234 1.6 mycroft
235 1.6 mycroft /* config.c */
236 1.6 mycroft extern void config_vifs_from_kernel __P((void));
237 1.6 mycroft
238 1.6 mycroft /* cfparse.y */
239 1.6 mycroft extern void config_vifs_from_file __P((void));
240 1.6 mycroft
241 1.6 mycroft /* inet.c */
242 1.6 mycroft extern int inet_valid_host __P((u_int32_t naddr));
243 1.7 lukem extern int inet_valid_mask __P((u_int32_t mask));
244 1.6 mycroft extern int inet_valid_subnet __P((u_int32_t nsubnet, u_int32_t nmask));
245 1.6 mycroft extern char * inet_fmt __P((u_int32_t addr, char *s));
246 1.6 mycroft extern char * inet_fmts __P((u_int32_t addr, u_int32_t mask, char *s));
247 1.6 mycroft extern u_int32_t inet_parse __P((char *s));
248 1.6 mycroft extern int inet_cksum __P((u_short *addr, u_int len));
249 1.6 mycroft
250 1.6 mycroft /* prune.c */
251 1.4 mycroft extern unsigned kroutes;
252 1.6 mycroft extern void add_table_entry __P((u_int32_t origin, u_int32_t mcastgrp));
253 1.6 mycroft extern void del_table_entry __P((struct rtentry *r,
254 1.6 mycroft u_int32_t mcastgrp, u_int del_flag));
255 1.6 mycroft extern void update_table_entry __P((struct rtentry *r));
256 1.6 mycroft extern void init_ktable __P((void));
257 1.6 mycroft extern void accept_prune __P((u_int32_t src, u_int32_t dst, char *p,
258 1.6 mycroft int datalen));
259 1.6 mycroft extern void steal_sources __P((struct rtentry *rt));
260 1.6 mycroft extern void reset_neighbor_state __P((vifi_t vifi, u_int32_t addr));
261 1.6 mycroft extern int grplst_mem __P((vifi_t vifi, u_int32_t mcastgrp));
262 1.6 mycroft extern int scoped_addr __P((vifi_t vifi, u_int32_t addr));
263 1.6 mycroft extern void free_all_prunes __P((void));
264 1.6 mycroft extern void age_table_entry __P((void));
265 1.6 mycroft extern void dump_cache __P((FILE *fp2));
266 1.6 mycroft extern void update_lclgrp __P((vifi_t vifi, u_int32_t mcastgrp));
267 1.6 mycroft extern void delete_lclgrp __P((vifi_t vifi, u_int32_t mcastgrp));
268 1.6 mycroft extern void chkgrp_graft __P((vifi_t vifi, u_int32_t mcastgrp));
269 1.6 mycroft extern void accept_graft __P((u_int32_t src, u_int32_t dst, char *p,
270 1.6 mycroft int datalen));
271 1.6 mycroft extern void accept_g_ack __P((u_int32_t src, u_int32_t dst, char *p,
272 1.6 mycroft int datalen));
273 1.6 mycroft /* u_int is promoted u_char */
274 1.6 mycroft extern void accept_mtrace __P((u_int32_t src, u_int32_t dst,
275 1.6 mycroft u_int32_t group, char *data, u_int no,
276 1.6 mycroft int datalen));
277 1.7 lukem extern int find_src_grp __P((u_int32_t, u_int32_t, u_int32_t));
278 1.6 mycroft
279 1.6 mycroft /* kern.c */
280 1.6 mycroft extern void k_set_rcvbuf __P((int bufsize));
281 1.6 mycroft extern void k_hdr_include __P((int bool));
282 1.6 mycroft extern void k_set_ttl __P((int t));
283 1.6 mycroft extern void k_set_loop __P((int l));
284 1.6 mycroft extern void k_set_if __P((u_int32_t ifa));
285 1.6 mycroft extern void k_join __P((u_int32_t grp, u_int32_t ifa));
286 1.6 mycroft extern void k_leave __P((u_int32_t grp, u_int32_t ifa));
287 1.6 mycroft extern void k_init_dvmrp __P((void));
288 1.6 mycroft extern void k_stop_dvmrp __P((void));
289 1.6 mycroft extern void k_add_vif __P((vifi_t vifi, struct uvif *v));
290 1.6 mycroft extern void k_del_vif __P((vifi_t vifi));
291 1.6 mycroft extern void k_add_rg __P((u_int32_t origin, struct gtable *g));
292 1.6 mycroft extern int k_del_rg __P((u_int32_t origin, struct gtable *g));
293 1.6 mycroft extern int k_get_version __P((void));
294 1.4 mycroft
295 1.4 mycroft #ifdef SNMP
296 1.6 mycroft /* prune.c */
297 1.6 mycroft extern struct rtentry * snmp_find_route __P(());
298 1.6 mycroft extern struct gtable * find_grp __P(());
299 1.6 mycroft extern struct stable * find_grp_src __P(());
300 1.4 mycroft #endif
301 1.4 mycroft
302 1.4 mycroft #ifdef RSRR
303 1.6 mycroft /* prune.c */
304 1.4 mycroft extern struct gtable *kernel_table;
305 1.4 mycroft extern struct gtable *gtp;
306 1.6 mycroft extern int find_src_grp __P((u_int32_t src, u_int32_t mask,
307 1.6 mycroft u_int32_t grp));
308 1.4 mycroft
309 1.6 mycroft /* rsrr.c */
310 1.6 mycroft extern void rsrr_init __P((void));
311 1.6 mycroft extern void rsrr_read __P((int f, fd_set *rfd));
312 1.6 mycroft extern void rsrr_clean __P((void));
313 1.6 mycroft extern void rsrr_cache_send __P((struct gtable *gt, int notify));
314 1.6 mycroft extern void rsrr_cache_clean __P((struct gtable *gt));
315 1.4 mycroft #endif /* RSRR */
316 1.7 lukem
317 1.7 lukem /* vif.c */
318 1.7 lukem extern void accept_info_reply __P((u_int32_t, u_int32_t,
319 1.7 lukem u_char *, int));
320 1.7 lukem extern void accept_info_request __P((u_int32_t, u_int32_t,
321 1.7 lukem u_char *, int));
322 1.7 lukem extern void init_installvifs __P((void));
323