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