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