Home | History | Annotate | Line # | Download | only in mrouted
defs.h revision 1.9
      1  1.9      wiz /*	$NetBSD: defs.h,v 1.9 2002/07/14 16:30:42 wiz 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.1   brezak extern int		igmp_socket;
    105  1.4  mycroft #ifdef RSRR
    106  1.4  mycroft extern int              rsrr_socket;
    107  1.4  mycroft #endif /* RSRR */
    108  1.4  mycroft extern u_int32_t	allhosts_group;
    109  1.4  mycroft extern u_int32_t	allrtrs_group;
    110  1.4  mycroft extern u_int32_t	dvmrp_group;
    111  1.4  mycroft extern u_int32_t	dvmrp_genid;
    112  1.1   brezak 
    113  1.1   brezak #define DEFAULT_DEBUG  2	/* default if "-d" given without value */
    114  1.1   brezak 
    115  1.1   brezak extern int		debug;
    116  1.4  mycroft extern u_char		pruning;
    117  1.1   brezak 
    118  1.1   brezak extern int		routes_changed;
    119  1.1   brezak extern int		delay_change_reports;
    120  1.2   brezak extern unsigned		nroutes;
    121  1.1   brezak 
    122  1.1   brezak extern struct uvif	uvifs[MAXVIFS];
    123  1.1   brezak extern vifi_t		numvifs;
    124  1.1   brezak extern int		vifs_down;
    125  1.1   brezak extern int		udp_socket;
    126  1.4  mycroft extern int		vifs_with_neighbors;
    127  1.1   brezak 
    128  1.1   brezak extern char		s1[];
    129  1.1   brezak extern char		s2[];
    130  1.1   brezak extern char		s3[];
    131  1.4  mycroft extern char		s4[];
    132  1.1   brezak 
    133  1.6  mycroft #if !(defined(BSD) && (BSD >= 199103))
    134  1.6  mycroft extern int		errno;
    135  1.6  mycroft extern int		sys_nerr;
    136  1.6  mycroft extern char *		sys_errlist[];
    137  1.6  mycroft #endif
    138  1.1   brezak 
    139  1.6  mycroft #ifdef OLD_KERNEL
    140  1.6  mycroft #define	MRT_INIT	DVMRP_INIT
    141  1.6  mycroft #define	MRT_DONE	DVMRP_DONE
    142  1.6  mycroft #define	MRT_ADD_VIF	DVMRP_ADD_VIF
    143  1.6  mycroft #define	MRT_DEL_VIF	DVMRP_DEL_VIF
    144  1.6  mycroft #define	MRT_ADD_MFC	DVMRP_ADD_MFC
    145  1.6  mycroft #define	MRT_DEL_MFC	DVMRP_DEL_MFC
    146  1.4  mycroft 
    147  1.6  mycroft #define	IGMP_PIM	0x14
    148  1.6  mycroft #endif
    149  1.6  mycroft 
    150  1.6  mycroft /* main.c */
    151  1.9      wiz extern void		log(int, int, const char *, ...)
    152  1.8       is 	__attribute__((__format__(__printf__, 3, 4)));
    153  1.9      wiz extern int		register_input_handler(int fd, ihfunc_t func);
    154  1.6  mycroft 
    155  1.6  mycroft /* igmp.c */
    156  1.9      wiz extern void		init_igmp(void);
    157  1.9      wiz extern void		accept_igmp(int recvlen);
    158  1.9      wiz extern void		send_igmp(u_int32_t src, u_int32_t dst, int type,
    159  1.9      wiz 				  int code, u_int32_t group, int datalen);
    160  1.6  mycroft 
    161  1.6  mycroft /* callout.c */
    162  1.9      wiz extern void		callout_init(void);
    163  1.9      wiz extern void		age_callout_queue(void);
    164  1.9      wiz extern int		timer_setTimer(int delay, cfunc_t action, char *data);
    165  1.9      wiz extern void		timer_clearTimer(int timer_id);
    166  1.6  mycroft 
    167  1.6  mycroft /* route.c */
    168  1.9      wiz extern void		init_routes(void);
    169  1.9      wiz extern void		start_route_updates(void);
    170  1.9      wiz extern void		update_route(u_int32_t origin, u_int32_t mask,
    171  1.9      wiz 				     u_int metric, u_int32_t src, vifi_t vifi);
    172  1.9      wiz extern void		age_routes(void);
    173  1.9      wiz extern void		expire_all_routes(void);
    174  1.9      wiz extern void		free_all_routes(void);
    175  1.9      wiz extern void		accept_probe(u_int32_t src, u_int32_t dst,
    176  1.9      wiz 				     char *p, int datalen, u_int32_t level);
    177  1.9      wiz extern void		accept_report(u_int32_t src, u_int32_t dst,
    178  1.9      wiz 				      char *p, int datalen, u_int32_t level);
    179  1.9      wiz extern struct rtentry *	determine_route(u_int32_t src);
    180  1.9      wiz extern void		report(int which_routes, vifi_t vifi, u_int32_t dst);
    181  1.9      wiz extern void		report_to_all_neighbors(int which_routes);
    182  1.9      wiz extern int		report_next_chunk(void);
    183  1.9      wiz extern void		add_vif_to_routes(vifi_t vifi);
    184  1.9      wiz extern void		delete_vif_from_routes(vifi_t vifi);
    185  1.9      wiz extern void		delete_neighbor_from_routes(u_int32_t addr,
    186  1.9      wiz 						    vifi_t vifi);
    187  1.9      wiz extern void		dump_routes(FILE *fp);
    188  1.9      wiz extern void		start_route_updates(void);
    189  1.6  mycroft 
    190  1.6  mycroft /* vif.c */
    191  1.9      wiz extern void		init_vifs(void);
    192  1.9      wiz extern void		check_vif_state(void);
    193  1.9      wiz extern vifi_t		find_vif(u_int32_t src, u_int32_t dst);
    194  1.9      wiz extern void		age_vifs(void);
    195  1.9      wiz extern void		dump_vifs(FILE *fp);
    196  1.9      wiz extern void		stop_all_vifs(void);
    197  1.9      wiz extern struct listaddr *neighbor_info(vifi_t vifi, u_int32_t addr);
    198  1.9      wiz extern void		accept_group_report(u_int32_t src, u_int32_t dst,
    199  1.9      wiz 					    u_int32_t group, int r_type);
    200  1.9      wiz extern void		query_groups(void);
    201  1.9      wiz extern void		probe_for_neighbors(void);
    202  1.9      wiz extern int		update_neighbor(vifi_t vifi, u_int32_t addr,
    203  1.6  mycroft 					int msgtype, char *p, int datalen,
    204  1.9      wiz 					u_int32_t level);
    205  1.9      wiz extern void		accept_neighbor_request(u_int32_t src, u_int32_t dst);
    206  1.9      wiz extern void		accept_neighbor_request2(u_int32_t src, u_int32_t dst);
    207  1.9      wiz extern void		accept_neighbors(u_int32_t src, u_int32_t dst,
    208  1.9      wiz 					 u_char *p, int datalen,
    209  1.9      wiz 					 u_int32_t level);
    210  1.9      wiz extern void		accept_neighbors2(u_int32_t src, u_int32_t dst,
    211  1.9      wiz 					  u_char *p, int datalen,
    212  1.9      wiz 					  u_int32_t level);
    213  1.9      wiz extern void		accept_leave_message(u_int32_t src, u_int32_t dst,
    214  1.9      wiz 					     u_int32_t group);
    215  1.9      wiz extern void		accept_membership_query(u_int32_t src, u_int32_t dst,
    216  1.9      wiz 						u_int32_t group, int tmo);
    217  1.6  mycroft 
    218  1.6  mycroft /* config.c */
    219  1.9      wiz extern void		config_vifs_from_kernel(void);
    220  1.6  mycroft 
    221  1.6  mycroft /* cfparse.y */
    222  1.9      wiz extern void		config_vifs_from_file(void);
    223  1.6  mycroft 
    224  1.6  mycroft /* inet.c */
    225  1.9      wiz extern int		inet_valid_host(u_int32_t naddr);
    226  1.9      wiz extern int		inet_valid_mask(u_int32_t mask);
    227  1.9      wiz extern int		inet_valid_subnet(u_int32_t nsubnet, u_int32_t nmask);
    228  1.9      wiz extern char *		inet_fmt(u_int32_t addr, char *s);
    229  1.9      wiz extern char *		inet_fmts(u_int32_t addr, u_int32_t mask, char *s);
    230  1.9      wiz extern u_int32_t	inet_parse(char *s);
    231  1.9      wiz extern int		inet_cksum(u_short *addr, u_int len);
    232  1.6  mycroft 
    233  1.6  mycroft /* prune.c */
    234  1.4  mycroft extern unsigned		kroutes;
    235  1.9      wiz extern void		add_table_entry(u_int32_t origin, u_int32_t mcastgrp);
    236  1.9      wiz extern void 		del_table_entry(struct rtentry *r,
    237  1.9      wiz 					u_int32_t mcastgrp, u_int del_flag);
    238  1.9      wiz extern void		update_table_entry(struct rtentry *r);
    239  1.9      wiz extern void		init_ktable(void);
    240  1.9      wiz extern void 		accept_prune(u_int32_t src, u_int32_t dst, char *p,
    241  1.9      wiz 				     int datalen);
    242  1.9      wiz extern void		steal_sources(struct rtentry *rt);
    243  1.9      wiz extern void		reset_neighbor_state(vifi_t vifi, u_int32_t addr);
    244  1.9      wiz extern int		grplst_mem(vifi_t vifi, u_int32_t mcastgrp);
    245  1.9      wiz extern int		scoped_addr(vifi_t vifi, u_int32_t addr);
    246  1.9      wiz extern void		free_all_prunes(void);
    247  1.9      wiz extern void 		age_table_entry(void);
    248  1.9      wiz extern void		dump_cache(FILE *fp2);
    249  1.9      wiz extern void 		update_lclgrp(vifi_t vifi, u_int32_t mcastgrp);
    250  1.9      wiz extern void		delete_lclgrp(vifi_t vifi, u_int32_t mcastgrp);
    251  1.9      wiz extern void		chkgrp_graft(vifi_t vifi, u_int32_t mcastgrp);
    252  1.9      wiz extern void		accept_graft(u_int32_t src, u_int32_t dst, char *p,
    253  1.9      wiz 				     int datalen);
    254  1.9      wiz extern void 		accept_g_ack(u_int32_t src, u_int32_t dst, char *p,
    255  1.9      wiz 				     int datalen);
    256  1.6  mycroft /* u_int is promoted u_char */
    257  1.9      wiz extern void		accept_mtrace(u_int32_t src, u_int32_t dst,
    258  1.9      wiz 				      u_int32_t group, char *data, u_int no,
    259  1.9      wiz 				      int datalen);
    260  1.9      wiz extern int		find_src_grp(u_int32_t, u_int32_t, u_int32_t);
    261  1.6  mycroft 
    262  1.6  mycroft /* kern.c */
    263  1.9      wiz extern void		k_set_rcvbuf(int bufsize);
    264  1.9      wiz extern void		k_hdr_include(int bool);
    265  1.9      wiz extern void		k_set_ttl(int t);
    266  1.9      wiz extern void		k_set_loop(int l);
    267  1.9      wiz extern void		k_set_if(u_int32_t ifa);
    268  1.9      wiz extern void		k_join(u_int32_t grp, u_int32_t ifa);
    269  1.9      wiz extern void		k_leave(u_int32_t grp, u_int32_t ifa);
    270  1.9      wiz extern void		k_init_dvmrp(void);
    271  1.9      wiz extern void		k_stop_dvmrp(void);
    272  1.9      wiz extern void		k_add_vif(vifi_t vifi, struct uvif *v);
    273  1.9      wiz extern void		k_del_vif(vifi_t vifi);
    274  1.9      wiz extern void		k_add_rg(u_int32_t origin, struct gtable *g);
    275  1.9      wiz extern int		k_del_rg(u_int32_t origin, struct gtable *g);
    276  1.9      wiz extern int		k_get_version(void);
    277  1.4  mycroft 
    278  1.4  mycroft #ifdef SNMP
    279  1.6  mycroft /* prune.c */
    280  1.9      wiz extern struct rtentry * snmp_find_route();
    281  1.9      wiz extern struct gtable *	find_grp();
    282  1.9      wiz extern struct stable *	find_grp_src();
    283  1.4  mycroft #endif
    284  1.4  mycroft 
    285  1.4  mycroft #ifdef RSRR
    286  1.6  mycroft /* prune.c */
    287  1.4  mycroft extern struct gtable	*kernel_table;
    288  1.4  mycroft extern struct gtable	*gtp;
    289  1.9      wiz extern int		find_src_grp(u_int32_t src, u_int32_t mask,
    290  1.9      wiz 				     u_int32_t grp);
    291  1.4  mycroft 
    292  1.6  mycroft /* rsrr.c */
    293  1.9      wiz extern void		rsrr_init(void);
    294  1.9      wiz extern void		rsrr_read(int f, fd_set *rfd);
    295  1.9      wiz extern void		rsrr_clean(void);
    296  1.9      wiz extern void		rsrr_cache_send(struct gtable *gt, int notify);
    297  1.9      wiz extern void		rsrr_cache_clean(struct gtable *gt);
    298  1.4  mycroft #endif /* RSRR */
    299  1.7    lukem 
    300  1.7    lukem /* vif.c */
    301  1.9      wiz extern void		accept_info_reply(u_int32_t, u_int32_t, u_char *, int);
    302  1.9      wiz extern void		accept_info_request(u_int32_t, u_int32_t,
    303  1.9      wiz 					    u_char *, int);
    304  1.9      wiz extern void		init_installvifs(void);
    305