Annotation of embedaddon/pimdd/defs.h, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (c) 1998 by the University of Oregon.
3: * All rights reserved.
4: *
5: * Permission to use, copy, modify, and distribute this software and
6: * its documentation in source and binary forms for lawful
7: * purposes and without fee is hereby granted, provided
8: * that the above copyright notice appear in all copies and that both
9: * the copyright notice and this permission notice appear in supporting
10: * documentation, and that any documentation, advertising materials,
11: * and other materials related to such distribution and use acknowledge
12: * that the software was developed by the University of Oregon.
13: * The name of the University of Oregon may not be used to endorse or
14: * promote products derived from this software without specific prior
15: * written permission.
16: *
17: * THE UNIVERSITY OF OREGON DOES NOT MAKE ANY REPRESENTATIONS
18: * ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. THIS SOFTWARE IS
19: * PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
20: * INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND
22: * NON-INFRINGEMENT.
23: *
24: * IN NO EVENT SHALL UO, OR ANY OTHER CONTRIBUTOR BE LIABLE FOR ANY
25: * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, WHETHER IN CONTRACT,
26: * TORT, OR OTHER FORM OF ACTION, ARISING OUT OF OR IN CONNECTION WITH,
27: * THE USE OR PERFORMANCE OF THIS SOFTWARE.
28: *
29: * Other copyrights might apply to parts of this software and are so
30: * noted when applicable.
31: */
32: /*
33: * Questions concerning this software should be directed to
34: * Kurt Windisch (kurtw@antc.uoregon.edu)
35: *
36: * $Id: defs.h,v 1.18 1998/12/22 21:50:17 kurtw Exp $
37: */
38: /*
39: * Part of this program has been derived from PIM sparse-mode pimd.
40: * The pimd program is covered by the license in the accompanying file
41: * named "LICENSE.pimd".
42: *
43: * The pimd program is COPYRIGHT 1998 by University of Southern California.
44: *
45: * Part of this program has been derived from mrouted.
46: * The mrouted program is covered by the license in the accompanying file
47: * named "LICENSE.mrouted".
48: *
49: * The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
50: * Leland Stanford Junior University.
51: *
52: */
53:
54: #include <stdio.h>
55: #include <stdlib.h>
56: #include <unistd.h>
57: #include <ctype.h>
58: #include <errno.h>
59: #include <syslog.h>
60: #include <signal.h>
61: #include <string.h>
62: #include <sys/param.h>
63: #include <sys/types.h>
64: #include <sys/socket.h>
65: #include <sys/ioctl.h>
66: #include <fcntl.h>
67: #if ((defined(SYSV)) || (defined(BSDI)) || ((defined SunOS) && (SunOS < 50)))
68: #include <sys/sockio.h>
69: #endif /* SYSV || BSDI || SunOS 4.x */
70: #include <sys/time.h>
71: #include <net/if.h>
72: #include <netinet/in.h>
73: #include <netinet/in_systm.h>
74: #include <netinet/ip.h>
75: #include <netinet/igmp.h>
76: #ifdef __FreeBSD__ /* sigh */
77: #include <osreldate.h>
78: #endif /* __FreeBSD__ */
79: #if (defined(BSDI)) || (defined(__FreeBSD__) && (__FreeBSD_version >= 220000))
80: #define rtentry kernel_rtentry
81: #include <net/route.h>
82: #undef rtentry
83: #endif /* BSDI or __FreeBSD_version >= 220000 */
84: #include <netinet/ip_mroute.h>
85: #include <strings.h>
86: #ifdef RSRR
87: #include <sys/un.h>
88: #endif /* RSRR */
89:
90: typedef u_int u_int32;
91: typedef u_short u_int16;
92: typedef u_char u_int8;
93:
94: #ifndef __P
95: #ifdef __STDC__
96: #define __P(x) x
97: #else
98: #define __P(x) ()
99: #endif
100: #endif
101:
102: typedef void (*cfunc_t) __P((void *));
103: typedef void (*ihfunc_t) __P((int, fd_set *));
104:
105: #include "dvmrp.h" /* Added for further compatibility and convenience */
106: #include "pimdd.h"
107: #include "mrt.h"
108: #include "igmpv2.h"
109: #include "vif.h"
110: #include "debug.h"
111: #include "pathnames.h"
112: #ifdef RSRR
113: #include "rsrr.h"
114: #include "rsrr_var.h"
115: #endif /* RSRR */
116:
117: /*
118: * Miscellaneous constants and macros
119: */
120: /* #if (!(defined(BSDI)) && !(defined(KERNEL))) */
121: #ifndef KERNEL
122: #define max(a, b) ((a) < (b) ? (b) : (a))
123: #define min(a, b) ((a) > (b) ? (b) : (a))
124: #endif
125:
126: /*
127: * Various definitions to make it working for different platforms
128: */
129: /* The old style sockaddr definition doesn't have sa_len */
130: #if (defined(BSD) && (BSD >= 199006)) /* sa_len was added with 4.3-Reno */
131: #define HAVE_SA_LEN
132: #endif
133:
134: /* Versions of Solaris older than 2.6 don't have routing sockets. */
135: /* XXX TODO: check FreeBSD version and add all other platforms */
136: #if ((defined(SunOS) && SunOS >=56) || (defined FreeBSD) || (defined IRIX) || (defined BSDI) || defined(NetBSD))
137: #define HAVE_ROUTING_SOCKETS
138: #endif
139:
140: #define TRUE 1
141: #define FALSE 0
142:
143: #ifndef MAX
144: #define MAX(a,b) (((a) >= (b))? (a) : (b))
145: #define MIN(a,b) (((a) <= (b))? (a) : (b))
146: #endif /* MAX & MIN */
147:
148: #define CREATE TRUE
149: #define DONT_CREATE FALSE
150:
151: #define EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
152:
153: /* obnoxious gcc gives an extraneous warning about this constant... */
154: #if defined(__STDC__) || defined(__GNUC__)
155: #define JAN_1970 2208988800UL /* 1970 - 1900 in seconds */
156: #else
157: #define JAN_1970 2208988800L /* 1970 - 1900 in seconds */
158: #define const /**/
159: #endif
160:
161:
162: #define MINTTL 1 /* min TTL in the packets send locally */
163:
164: #define MAX_IP_PACKET_LEN 576
165: #define MIN_IP_HEADER_LEN 20
166: #define MAX_IP_HEADER_LEN 60
167:
168:
169: /*
170: * The IGMPv2 <netinet/in.h> defines INADDR_ALLRTRS_GROUP, but earlier
171: * ones don't, so we define it conditionally here.
172: */
173: #ifndef INADDR_ALLRTRS_GROUP
174: /* address for multicast mtrace msg */
175: #define INADDR_ALLRTRS_GROUP (u_int32)0xe0000002 /* 224.0.0.2 */
176: #endif
177:
178: #ifndef INADDR_MAX_LOCAL_GROUP
179: define INADDR_MAX_LOCAL_GROUP (u_int32)0xe00000ff /* 224.0.0.255 */
180: #endif
181:
182: #define INADDR_ANY_N (u_int32)0x00000000 /* INADDR_ANY in
183: * network order */
184: #define CLASSD_PREFIX (u_int32)0xe0000000 /* 224.0.0.0 */
185: #define ALL_MCAST_GROUPS_ADDR (u_int32)0xe0000000 /* 224.0.0.0 */
186: #define ALL_MCAST_GROUPS_LENGTH 4
187:
188: /* Used by DVMRP */
189: #define DEFAULT_METRIC 1 /* default subnet/tunnel metric */
190: #define DEFAULT_THRESHOLD 1 /* default subnet/tunnel threshold */
191:
192: #define TIMER_INTERVAL 5 /* 5 sec virtual timer granularity */
193:
194: #ifdef RSRR
195: #define BIT_ZERO(X) ((X) = 0)
196: #define BIT_SET(X,n) ((X) |= 1 << (n))
197: #define BIT_CLR(X,n) ((X) &= ~(1 << (n)))
198: #define BIT_TST(X,n) ((X) & 1 << (n))
199: #endif /* RSRR */
200:
201: #ifdef SYSV
202: #define bcopy(a, b, c) memcpy((b), (a), (c))
203: #define bzero(s, n) memset((s), 0, (n))
204: #define setlinebuf(s) setvbuf((s), (NULL), (_IOLBF), 0)
205: #define RANDOM() lrand48()
206: #else
207: #define RANDOM() random()
208: #endif /* SYSV */
209:
210: /*
211: * External declarations for global variables and functions.
212: */
213: #define RECV_BUF_SIZE 64*1024 /* Maximum buff size to send
214: * or receive packet */
215: #define SO_RECV_BUF_SIZE_MAX 256*1024
216: #define SO_RECV_BUF_SIZE_MIN 48*1024
217:
218: /* TODO: describe the variables and clean up */
219: extern char *igmp_recv_buf;
220: extern char *igmp_send_buf;
221: extern char *pim_recv_buf;
222: extern char *pim_send_buf;
223: extern int igmp_socket;
224: extern int pim_socket;
225: extern u_int32 allhosts_group;
226: extern u_int32 allrouters_group;
227: extern u_int32 allpimrouters_group;
228: extern vifbitmap_t nbr_vifs;
229:
230: #ifdef RSRR
231: extern int rsrr_socket;
232: #endif /* RSRR */
233:
234: extern u_long virtual_time;
235: extern char configfilename[];
236:
237: extern u_int32 default_source_metric;
238: extern u_int32 default_source_preference;
239:
240: extern srcentry_t *srclist;
241: extern grpentry_t *grplist;
242:
243: extern struct uvif uvifs[MAXVIFS];
244: extern vifi_t numvifs;
245: extern int total_interfaces;
246: extern int phys_vif;
247: extern int udp_socket;
248:
249: extern int vifs_down;
250:
251: extern char s1[];
252: extern char s2[];
253: extern char s3[];
254: extern char s4[];
255:
256: #if !((defined(BSD) && (BSD >= 199103)) || defined(linux))
257: extern int errno;
258: extern int sys_nerr;
259: extern char * sys_errlist[];
260: #endif
261:
262:
263: #ifndef IGMP_MEMBERSHIP_QUERY
264: #define IGMP_MEMBERSHIP_QUERY IGMP_HOST_MEMBERSHIP_QUERY
265: #if !(defined(NetBSD))
266: #define IGMP_V1_MEMBERSHIP_REPORT IGMP_HOST_MEMBERSHIP_REPORT
267: #define IGMP_V2_MEMBERSHIP_REPORT IGMP_HOST_NEW_MEMBERSHIP_REPORT
268: #else
269: #define IGMP_V1_MEMBERSHIP_REPORT IGMP_v1_HOST_MEMBERSHIP_REPORT
270: #define IGMP_V2_MEMBERSHIP_REPORT IGMP_v2_HOST_MEMBERSHIP_REPORT
271: #endif
272: #define IGMP_V2_LEAVE_GROUP IGMP_HOST_LEAVE_MESSAGE
273: #endif
274:
275: #if defined(NetBSD)
276: #define IGMP_MTRACE_RESP IGMP_MTRACE_REPLY
277: #define IGMP_MTRACE IGMP_MTRACE_QUERY
278: #endif
279:
280: /* For timeout. The timers count down */
281: #define SET_TIMER(timer, value) (timer) = (value)
282: #define RESET_TIMER(timer) (timer) = 0
283: #define COPY_TIMER(timer_1, timer_2) (timer_2) = (timer_1)
284: #define IF_TIMER_SET(timer) if ((timer) > 0)
285: #define IF_TIMER_NOT_SET(timer) if ((timer) <= 0)
286: #define FIRE_TIMER(timer) (timer) = 0
287:
288: /* XXX Timer will never decrement below 0 - does this work with age_routes?
289: */
290: #define IF_TIMEOUT(timer) \
291: if (!((timer) -= (MIN(timer, TIMER_INTERVAL))))
292:
293: #define IF_NOT_TIMEOUT(timer) \
294: if ((timer) -= (MIN(timer, TIMER_INTERVAL)))
295:
296: #define TIMEOUT(timer) \
297: (!((timer) -= (MIN(timer, TIMER_INTERVAL))))
298:
299: #define NOT_TIMEOUT(timer) \
300: ((timer) -= (MIN(timer, TIMER_INTERVAL)))
301:
302: #if 0
303: #define IF_TIMEOUT(value) \
304: if (!(((value) >= TIMER_INTERVAL) && ((value) -= TIMER_INTERVAL)))
305:
306: #define IF_NOT_TIMEOUT(value) \
307: if (((value) >= TIMER_INTERVAL) && ((value) -= TIMER_INTERVAL))
308:
309: #define TIMEOUT(value) \
310: (!(((value) >= TIMER_INTERVAL) && ((value) -= TIMER_INTERVAL)))
311:
312: #define NOT_TIMEOUT(value) \
313: (((value) >= TIMER_INTERVAL) && ((value) -= TIMER_INTERVAL))
314: #endif /* 0 */
315:
316: #define ELSE else /* To make emacs cc-mode happy */
317:
318:
319: /*
320: * External function definitions
321: */
322:
323: /* callout.c */
324: extern void callout_init __P((void));
325: extern void free_all_callouts __P((void));
326: extern void age_callout_queue __P((int));
327: extern int timer_nextTimer __P((void));
328: extern int timer_setTimer __P((int, cfunc_t, void *));
329: extern void timer_clearTimer __P((int));
330: extern int timer_leftTimer __P((int));
331:
332: /* config.c */
333: extern void config_vifs_from_kernel __P(());
334: extern void config_vifs_from_file __P(());
335:
336: /* debug.c */
337: extern char *packet_kind __P((u_int proto, u_int type, u_int code));
338: extern int debug_kind __P((u_int proto, u_int type, u_int code));
339: extern void log __P((int, int, char *, ...));
340: extern int log_level __P((u_int proto, u_int type, u_int code));
341: extern void dump __P((int i));
342: extern void fdump __P((int i));
343: extern void cdump __P((int i));
344: extern void dump_vifs __P((FILE *fp));
345: extern void dump_pim_mrt __P((FILE *fp));
346:
347: /* dvmrp_proto.c */
348: extern void dvmrp_accept_probe __P((u_int32 src, u_int32 dst,
349: char *p, int datalen,
350: u_int32 level));
351: extern void dvmrp_accept_report __P((u_int32 src, u_int32 dst,
352: char *p, int datalen,
353: u_int32 level));
354: extern void dvmrp_accept_info_request __P((u_int32 src, u_int32 dst,
355: u_char *p, int datalen));
356: extern void dvmrp_accept_info_reply __P((u_int32 src, u_int32 dst,
357: u_char *p, int datalen));
358: extern void dvmrp_accept_neighbors __P((u_int32 src, u_int32 dst,
359: u_char *p, int datalen,
360: u_int32 level));
361: extern void dvmrp_accept_neighbors2 __P((u_int32 src, u_int32 dst,
362: u_char *p, int datalen,
363: u_int32 level));
364: extern void dvmrp_accept_prune __P((u_int32 src, u_int32 dst,
365: char *p, int datalen));
366: extern void dvmrp_accept_graft __P((u_int32 src, u_int32 dst,
367: char *p, int datalen));
368: extern void dvmrp_accept_g_ack __P((u_int32 src, u_int32 dst,
369: char *p, int datalen));
370:
371: /* igmp.c */
372: extern void init_igmp __P(());
373: extern void send_igmp __P((char *buf, u_int32 src, u_int32 dst,
374: int type, int code, u_int32 group,
375: int datalen));
376:
377: /* igmp_proto.c */
378: extern void query_groups __P((struct uvif *v));
379: extern void accept_membership_query __P((u_int32 src, u_int32 dst,
380: u_int32 group, int tmo));
381: extern void accept_group_report __P((u_int32 src, u_int32 dst,
382: u_int32 group, int r_type));
383: extern void accept_leave_message __P((u_int32 src, u_int32 dst,
384: u_int32 group));
385: extern int check_grp_membership __P((struct uvif *v, u_int32 group));
386:
387: /* inet.c */
388: extern int inet_cksum __P((u_int16 *addr, u_int len));
389: extern int inet_valid_host __P((u_int32 naddr));
390: extern int inet_valid_mask __P((u_int32 mask));
391: extern int inet_valid_subnet __P((u_int32 nsubnet, u_int32 nmask));
392: extern char *inet_fmt __P((u_int32, char *s));
393: #ifdef NOSUCHDEF
394: extern char *inet_fmts __P((u_int32 addr, u_int32 mask, char *s));
395: #endif /* NOSUCHDEF */
396: extern char *netname __P((u_int32 addr, u_int32 mask));
397: extern u_int32 inet_parse __P((char *s, int n));
398:
399: /* kern.c */
400: extern void k_set_rcvbuf __P((int socket, int bufsize, int minsize));
401: extern void k_hdr_include __P((int socket, int bool));
402: extern void k_set_ttl __P((int socket, int t));
403: extern void k_set_loop __P((int socket, int l));
404: extern void k_set_if __P((int socket, u_int32 ifa));
405: extern void k_join __P((int socket, u_int32 grp, u_int32 ifa));
406: extern void k_leave __P((int socket, u_int32 grp, u_int32 ifa));
407: extern void k_init_pim __P(());
408: extern void k_stop_pim __P(());
409: extern int k_del_mfc __P((int socket, u_int32 source,
410: u_int32 group));
411: extern int k_chg_mfc __P((int socket, u_int32 source,
412: u_int32 group, vifi_t iif,
413: vifbitmap_t oifs));
414: extern void k_add_vif __P((int socket, vifi_t vifi, struct uvif *v));
415: extern void k_del_vif __P((int socket, vifi_t vifi));
416: extern int k_get_vif_count __P((vifi_t vifi, struct vif_count *retval));
417: extern int k_get_sg_cnt __P((int socket, u_int32 source,
418: u_int32 group, struct sg_count *retval));
419:
420: /* main.c */
421: extern int register_input_handler __P((int fd, ihfunc_t func));
422:
423: /* mrt.c */
424: extern void init_pim_mrt __P(());
425: extern mrtentry_t *find_route __P((u_int32 source,
426: u_int32 group,
427: u_int16 flags, char create));
428: extern grpentry_t *find_group __P((u_int32 group));
429: extern srcentry_t *find_source __P((u_int32 source));
430: extern void delete_mrtentry __P((mrtentry_t *mrtentry_ptr));
431: extern void delete_srcentry __P((srcentry_t *srcentry_ptr));
432: extern void delete_grpentry __P((grpentry_t *grpentry_ptr));
433:
434: /* pim.c */
435: extern void init_pim __P(());
436: extern void send_pim __P((char *buf, u_int32 src, u_int32 dst,
437: int type, int datalen));
438: extern void send_pim_unicast __P((char *buf, u_int32 src, u_int32 dst,
439: int type, int datalen));
440:
441: /* pim_proto.c */
442: extern int receive_pim_hello __P((u_int32 src, u_int32 dst,
443: char *pim_message, int datalen));
444: extern int send_pim_hello __P((struct uvif *v, u_int16 holdtime));
445: extern void delete_pim_nbr __P((pim_nbr_entry_t *nbr_delete));
446: extern int receive_pim_join_prune __P((u_int32 src, u_int32 dst,
447: char *pim_message, int datalen));
448: extern int send_pim_jp __P((mrtentry_t *mrtentry_ptr, int action,
449: vifi_t vifi, u_int32 target_addr,
450: u_int16 holdtime));
451: extern int receive_pim_assert __P((u_int32 src, u_int32 dst,
452: char *pim_message, int datalen));
453: extern int send_pim_assert __P((u_int32 source, u_int32 group,
454: vifi_t vifi,
455: u_int32 local_preference,
456: u_int32 local_metric));
457: extern void delete_pim_graft_entry __P((mrtentry_t *mrtentry_ptr));
458: extern int receive_pim_graft __P((u_int32 src, u_int32 dst,
459: char *pim_message, int datalen,
460: int pimtype));
461: extern int send_pim_graft __P((mrtentry_t *mrtentry_ptr));
462:
463:
464: /* route.c */
465: extern int set_incoming __P((srcentry_t *srcentry_ptr,
466: int srctype));
467: extern vifi_t get_iif __P((u_int32 source));
468: extern pim_nbr_entry_t *find_pim_nbr __P((u_int32 source));
469: extern int add_sg_oif __P((mrtentry_t *mrtentry_ptr,
470: vifi_t vifi,
471: u_int16 holdtime,
472: int update_holdtime));
473: extern void add_leaf __P((vifi_t vifi, u_int32 source,
474: u_int32 group));
475: extern void delete_leaf __P((vifi_t vifi, u_int32 source,
476: u_int32 group));
477: extern void set_leaves __P((mrtentry_t *mrtentry_ptr));
478: extern int change_interfaces __P((mrtentry_t *mrtentry_ptr,
479: vifi_t new_iif,
480: vifbitmap_t new_pruned_oifs,
481: vifbitmap_t new_leaves_));
482: extern void calc_oifs __P((mrtentry_t *mrtentry_ptr,
483: vifbitmap_t *oifs_ptr));
484: extern void process_kernel_call __P(());
485: extern int delete_vif_from_mrt __P((vifi_t vifi));
486: extern void trigger_join_alert __P((mrtentry_t *mrtentry_ptr));
487: extern void trigger_prune_alert __P((mrtentry_t *mrtentry_ptr));
488:
489:
490: /* routesock.c */
491: extern int k_req_incoming __P((u_int32 source,
492: struct rpfctl *rpfp));
493: #ifdef HAVE_ROUTING_SOCKETS
494: extern int init_routesock __P(());
495: #endif /* HAVE_ROUTING_SOCKETS */
496:
497: #ifdef RSRR
498: #define gtable mrtentry
499: #define RSRR_NOTIFICATION_OK TRUE
500: #define RSRR_NOTIFICATION_FALSE FALSE
501:
502: /* rsrr.c */
503: extern void rsrr_init __P((void));
504: extern void rsrr_clean __P((void));
505: extern void rsrr_cache_send __P((struct gtable *, int));
506: extern void rsrr_cache_clean __P((struct gtable *));
507: extern void rsrr_cache_bring_up __P((struct gtable *));
508: #endif /* RSRR */
509:
510: /* timer.c */
511: extern void init_timers __P(());
512: extern void age_vifs __P(());
513: extern void age_routes __P(());
514: extern int clean_srclist __P(());
515:
516: /* trace.c */
517: /* u_int is promoted u_char */
518: extern void accept_mtrace __P((u_int32 src, u_int32 dst,
519: u_int32 group, char *data,
520: u_int no, int datalen));
521: extern void accept_neighbor_request __P((u_int32 src, u_int32 dst));
522: extern void accept_neighbor_request2 __P((u_int32 src, u_int32 dst));
523:
524: /* vif.c */
525: extern void init_vifs __P(());
526: extern void stop_all_vifs __P(());
527: extern void check_vif_state __P(());
528: extern vifi_t local_address __P((u_int32 src));
529: extern vifi_t find_vif_direct __P((u_int32 src));
530: extern vifi_t find_vif_direct_local __P((u_int32 src));
531: extern u_int32 max_local_address __P((void));
532:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>