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