2002-10-01 07:30:50 +04:00
|
|
|
/* $NetBSD: defs.h,v 1.1 2002/10/01 03:31:06 itojun Exp $ */
|
1995-10-09 06:51:32 +03:00
|
|
|
|
1994-01-11 23:15:44 +03:00
|
|
|
/*
|
|
|
|
* The mrouted program is covered by the license in the accompanying file
|
|
|
|
* named "LICENSE". Use of the mrouted program represents acceptance of
|
|
|
|
* the terms and conditions listed in that file.
|
|
|
|
*
|
|
|
|
* The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
|
|
|
|
* Leland Stanford Junior University.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1995-12-10 13:06:55 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <string.h>
|
1994-01-11 23:15:44 +03:00
|
|
|
#include <sys/param.h>
|
1995-06-01 06:25:45 +04:00
|
|
|
#include <sys/types.h>
|
1994-01-11 23:15:44 +03:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
1995-12-10 13:06:55 +03:00
|
|
|
#ifdef SYSV
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#endif
|
1995-06-01 06:25:45 +04:00
|
|
|
#include <sys/time.h>
|
1994-01-11 23:15:44 +03:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/igmp.h>
|
|
|
|
#include <netinet/ip_mroute.h>
|
1995-06-01 06:25:45 +04:00
|
|
|
#ifdef RSRR
|
|
|
|
#include <sys/un.h>
|
|
|
|
#endif /* RSRR */
|
1994-01-11 23:15:44 +03:00
|
|
|
|
2002-07-14 20:30:41 +04:00
|
|
|
typedef void (*cfunc_t)(void *);
|
|
|
|
typedef void (*ihfunc_t)(int, fd_set *);
|
1995-12-10 13:06:55 +03:00
|
|
|
|
1994-01-11 23:15:44 +03:00
|
|
|
#include "dvmrp.h"
|
|
|
|
#include "vif.h"
|
|
|
|
#include "route.h"
|
1995-06-01 06:25:45 +04:00
|
|
|
#include "prune.h"
|
1994-01-11 23:15:44 +03:00
|
|
|
#include "pathnames.h"
|
1995-06-01 06:25:45 +04:00
|
|
|
#ifdef RSRR
|
|
|
|
#include "rsrr.h"
|
1995-12-10 13:06:55 +03:00
|
|
|
#include "rsrr_var.h"
|
1995-06-01 06:25:45 +04:00
|
|
|
#endif /* RSRR */
|
1994-01-11 23:15:44 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Miscellaneous constants and macros.
|
|
|
|
*/
|
|
|
|
#define FALSE 0
|
|
|
|
#define TRUE 1
|
|
|
|
|
|
|
|
#define EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
|
|
|
|
|
|
|
|
#define TIMER_INTERVAL ROUTE_MAX_REPORT_DELAY
|
|
|
|
|
1995-12-10 13:06:55 +03:00
|
|
|
#define VENDOR_CODE 1 /* Get a new vendor code if you make significant
|
|
|
|
* changes to mrouted. */
|
|
|
|
|
1995-06-01 06:25:45 +04:00
|
|
|
#define PROTOCOL_VERSION 3 /* increment when packet format/content changes */
|
1994-01-11 23:15:44 +03:00
|
|
|
|
1995-12-10 13:06:55 +03:00
|
|
|
#define MROUTED_VERSION 8 /* increment on local changes or bug fixes, */
|
1994-01-11 23:15:44 +03:00
|
|
|
/* reset to 0 whever PROTOCOL_VERSION increments */
|
|
|
|
|
1995-12-10 13:06:55 +03:00
|
|
|
#define MROUTED_LEVEL ((MROUTED_VERSION << 8) | PROTOCOL_VERSION | \
|
|
|
|
((NF_PRUNE | NF_GENID | NF_MTRACE) << 16) | \
|
|
|
|
(VENDOR_CODE << 24))
|
1994-01-11 23:15:44 +03:00
|
|
|
/* for IGMP 'group' field of DVMRP messages */
|
|
|
|
|
1995-06-01 06:25:45 +04:00
|
|
|
#define LEAF_FLAGS (( vifs_with_neighbors == 1 ) ? 0x010000 : 0)
|
|
|
|
/* more for IGMP 'group' field of DVMRP messages */
|
|
|
|
#define DEL_RTE_GROUP 0
|
|
|
|
#define DEL_ALL_ROUTES 1
|
|
|
|
/* for Deleting kernel table entries */
|
|
|
|
|
|
|
|
/* obnoxious gcc gives an extraneous warning about this constant... */
|
|
|
|
#define JAN_1970 2208988800UL /* 1970 - 1900 in seconds */
|
|
|
|
|
|
|
|
#ifdef RSRR
|
|
|
|
#define BIT_ZERO(X) ((X) = 0)
|
|
|
|
#define BIT_SET(X,n) ((X) |= 1 << (n))
|
|
|
|
#define BIT_CLR(X,n) ((X) &= ~(1 << (n)))
|
|
|
|
#define BIT_TST(X,n) ((X) & 1 << (n))
|
|
|
|
#endif /* RSRR */
|
|
|
|
|
1995-12-10 13:06:55 +03:00
|
|
|
#ifdef SYSV
|
|
|
|
#define bcopy(a, b, c) memcpy(b, a, c)
|
|
|
|
#define bzero(s, n) memset((s), 0, (n))
|
|
|
|
#define setlinebuf(s) setvbuf(s, NULL, _IOLBF, 0)
|
|
|
|
#define signal(s,f) sigset(s,f)
|
|
|
|
#endif
|
|
|
|
|
1994-01-11 23:15:44 +03:00
|
|
|
/*
|
|
|
|
* External declarations for global variables and functions.
|
|
|
|
*/
|
1995-12-10 13:06:55 +03:00
|
|
|
#define RECV_BUF_SIZE 8192
|
1995-06-01 06:25:45 +04:00
|
|
|
extern char *recv_buf;
|
|
|
|
extern char *send_buf;
|
1994-01-11 23:15:44 +03:00
|
|
|
extern int igmp_socket;
|
1995-06-01 06:25:45 +04:00
|
|
|
#ifdef RSRR
|
|
|
|
extern int rsrr_socket;
|
|
|
|
#endif /* RSRR */
|
|
|
|
extern u_int32_t allhosts_group;
|
|
|
|
extern u_int32_t allrtrs_group;
|
|
|
|
extern u_int32_t dvmrp_group;
|
|
|
|
extern u_int32_t dvmrp_genid;
|
1994-01-11 23:15:44 +03:00
|
|
|
|
|
|
|
#define DEFAULT_DEBUG 2 /* default if "-d" given without value */
|
|
|
|
|
|
|
|
extern int debug;
|
1995-06-01 06:25:45 +04:00
|
|
|
extern u_char pruning;
|
1994-01-11 23:15:44 +03:00
|
|
|
|
|
|
|
extern int routes_changed;
|
|
|
|
extern int delay_change_reports;
|
1994-05-08 19:08:52 +04:00
|
|
|
extern unsigned nroutes;
|
1994-01-11 23:15:44 +03:00
|
|
|
|
|
|
|
extern struct uvif uvifs[MAXVIFS];
|
|
|
|
extern vifi_t numvifs;
|
|
|
|
extern int vifs_down;
|
|
|
|
extern int udp_socket;
|
1995-06-01 06:25:45 +04:00
|
|
|
extern int vifs_with_neighbors;
|
1994-01-11 23:15:44 +03:00
|
|
|
|
|
|
|
extern char s1[];
|
|
|
|
extern char s2[];
|
|
|
|
extern char s3[];
|
1995-06-01 06:25:45 +04:00
|
|
|
extern char s4[];
|
1994-01-11 23:15:44 +03:00
|
|
|
|
1995-12-10 13:06:55 +03:00
|
|
|
#if !(defined(BSD) && (BSD >= 199103))
|
|
|
|
extern int errno;
|
|
|
|
extern int sys_nerr;
|
|
|
|
extern char * sys_errlist[];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OLD_KERNEL
|
|
|
|
#define MRT_INIT DVMRP_INIT
|
|
|
|
#define MRT_DONE DVMRP_DONE
|
|
|
|
#define MRT_ADD_VIF DVMRP_ADD_VIF
|
|
|
|
#define MRT_DEL_VIF DVMRP_DEL_VIF
|
|
|
|
#define MRT_ADD_MFC DVMRP_ADD_MFC
|
|
|
|
#define MRT_DEL_MFC DVMRP_DEL_MFC
|
1995-06-01 06:25:45 +04:00
|
|
|
|
1995-12-10 13:06:55 +03:00
|
|
|
#define IGMP_PIM 0x14
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* main.c */
|
2002-07-14 20:30:41 +04:00
|
|
|
extern void log(int, int, const char *, ...)
|
2000-10-12 00:23:46 +04:00
|
|
|
__attribute__((__format__(__printf__, 3, 4)));
|
2002-07-14 20:30:41 +04:00
|
|
|
extern int register_input_handler(int fd, ihfunc_t func);
|
1995-12-10 13:06:55 +03:00
|
|
|
|
|
|
|
/* igmp.c */
|
2002-07-14 20:30:41 +04:00
|
|
|
extern void init_igmp(void);
|
|
|
|
extern void accept_igmp(int recvlen);
|
|
|
|
extern void send_igmp(u_int32_t src, u_int32_t dst, int type,
|
|
|
|
int code, u_int32_t group, int datalen);
|
1995-12-10 13:06:55 +03:00
|
|
|
|
|
|
|
/* callout.c */
|
2002-07-14 20:30:41 +04:00
|
|
|
extern void callout_init(void);
|
|
|
|
extern void age_callout_queue(void);
|
|
|
|
extern int timer_setTimer(int delay, cfunc_t action, char *data);
|
|
|
|
extern void timer_clearTimer(int timer_id);
|
1995-12-10 13:06:55 +03:00
|
|
|
|
|
|
|
/* route.c */
|
2002-07-14 20:30:41 +04:00
|
|
|
extern void init_routes(void);
|
|
|
|
extern void start_route_updates(void);
|
|
|
|
extern void update_route(u_int32_t origin, u_int32_t mask,
|
|
|
|
u_int metric, u_int32_t src, vifi_t vifi);
|
|
|
|
extern void age_routes(void);
|
|
|
|
extern void expire_all_routes(void);
|
|
|
|
extern void free_all_routes(void);
|
|
|
|
extern void accept_probe(u_int32_t src, u_int32_t dst,
|
|
|
|
char *p, int datalen, u_int32_t level);
|
|
|
|
extern void accept_report(u_int32_t src, u_int32_t dst,
|
|
|
|
char *p, int datalen, u_int32_t level);
|
|
|
|
extern struct rtentry * determine_route(u_int32_t src);
|
|
|
|
extern void report(int which_routes, vifi_t vifi, u_int32_t dst);
|
|
|
|
extern void report_to_all_neighbors(int which_routes);
|
|
|
|
extern int report_next_chunk(void);
|
|
|
|
extern void add_vif_to_routes(vifi_t vifi);
|
|
|
|
extern void delete_vif_from_routes(vifi_t vifi);
|
|
|
|
extern void delete_neighbor_from_routes(u_int32_t addr,
|
|
|
|
vifi_t vifi);
|
|
|
|
extern void dump_routes(FILE *fp);
|
|
|
|
extern void start_route_updates(void);
|
1995-12-10 13:06:55 +03:00
|
|
|
|
|
|
|
/* vif.c */
|
2002-07-14 20:30:41 +04:00
|
|
|
extern void init_vifs(void);
|
|
|
|
extern void check_vif_state(void);
|
|
|
|
extern vifi_t find_vif(u_int32_t src, u_int32_t dst);
|
|
|
|
extern void age_vifs(void);
|
|
|
|
extern void dump_vifs(FILE *fp);
|
|
|
|
extern void stop_all_vifs(void);
|
|
|
|
extern struct listaddr *neighbor_info(vifi_t vifi, u_int32_t addr);
|
|
|
|
extern void accept_group_report(u_int32_t src, u_int32_t dst,
|
|
|
|
u_int32_t group, int r_type);
|
|
|
|
extern void query_groups(void);
|
|
|
|
extern void probe_for_neighbors(void);
|
|
|
|
extern int update_neighbor(vifi_t vifi, u_int32_t addr,
|
1995-12-10 13:06:55 +03:00
|
|
|
int msgtype, char *p, int datalen,
|
2002-07-14 20:30:41 +04:00
|
|
|
u_int32_t level);
|
|
|
|
extern void accept_neighbor_request(u_int32_t src, u_int32_t dst);
|
|
|
|
extern void accept_neighbor_request2(u_int32_t src, u_int32_t dst);
|
|
|
|
extern void accept_neighbors(u_int32_t src, u_int32_t dst,
|
|
|
|
u_char *p, int datalen,
|
|
|
|
u_int32_t level);
|
|
|
|
extern void accept_neighbors2(u_int32_t src, u_int32_t dst,
|
|
|
|
u_char *p, int datalen,
|
|
|
|
u_int32_t level);
|
|
|
|
extern void accept_leave_message(u_int32_t src, u_int32_t dst,
|
|
|
|
u_int32_t group);
|
|
|
|
extern void accept_membership_query(u_int32_t src, u_int32_t dst,
|
|
|
|
u_int32_t group, int tmo);
|
1995-12-10 13:06:55 +03:00
|
|
|
|
|
|
|
/* config.c */
|
2002-07-14 20:30:41 +04:00
|
|
|
extern void config_vifs_from_kernel(void);
|
1995-12-10 13:06:55 +03:00
|
|
|
|
|
|
|
/* cfparse.y */
|
2002-07-14 20:30:41 +04:00
|
|
|
extern void config_vifs_from_file(void);
|
1995-12-10 13:06:55 +03:00
|
|
|
|
|
|
|
/* inet.c */
|
2002-07-14 20:30:41 +04:00
|
|
|
extern int inet_valid_host(u_int32_t naddr);
|
|
|
|
extern int inet_valid_mask(u_int32_t mask);
|
|
|
|
extern int inet_valid_subnet(u_int32_t nsubnet, u_int32_t nmask);
|
|
|
|
extern char * inet_fmt(u_int32_t addr, char *s);
|
|
|
|
extern char * inet_fmts(u_int32_t addr, u_int32_t mask, char *s);
|
|
|
|
extern u_int32_t inet_parse(char *s);
|
|
|
|
extern int inet_cksum(u_short *addr, u_int len);
|
1995-12-10 13:06:55 +03:00
|
|
|
|
|
|
|
/* prune.c */
|
1995-06-01 06:25:45 +04:00
|
|
|
extern unsigned kroutes;
|
2002-07-14 20:30:41 +04:00
|
|
|
extern void add_table_entry(u_int32_t origin, u_int32_t mcastgrp);
|
|
|
|
extern void del_table_entry(struct rtentry *r,
|
|
|
|
u_int32_t mcastgrp, u_int del_flag);
|
|
|
|
extern void update_table_entry(struct rtentry *r);
|
|
|
|
extern void init_ktable(void);
|
|
|
|
extern void accept_prune(u_int32_t src, u_int32_t dst, char *p,
|
|
|
|
int datalen);
|
|
|
|
extern void steal_sources(struct rtentry *rt);
|
|
|
|
extern void reset_neighbor_state(vifi_t vifi, u_int32_t addr);
|
|
|
|
extern int grplst_mem(vifi_t vifi, u_int32_t mcastgrp);
|
|
|
|
extern int scoped_addr(vifi_t vifi, u_int32_t addr);
|
|
|
|
extern void free_all_prunes(void);
|
|
|
|
extern void age_table_entry(void);
|
|
|
|
extern void dump_cache(FILE *fp2);
|
|
|
|
extern void update_lclgrp(vifi_t vifi, u_int32_t mcastgrp);
|
|
|
|
extern void delete_lclgrp(vifi_t vifi, u_int32_t mcastgrp);
|
|
|
|
extern void chkgrp_graft(vifi_t vifi, u_int32_t mcastgrp);
|
|
|
|
extern void accept_graft(u_int32_t src, u_int32_t dst, char *p,
|
|
|
|
int datalen);
|
|
|
|
extern void accept_g_ack(u_int32_t src, u_int32_t dst, char *p,
|
|
|
|
int datalen);
|
1995-12-10 13:06:55 +03:00
|
|
|
/* u_int is promoted u_char */
|
2002-07-14 20:30:41 +04:00
|
|
|
extern void accept_mtrace(u_int32_t src, u_int32_t dst,
|
|
|
|
u_int32_t group, char *data, u_int no,
|
|
|
|
int datalen);
|
|
|
|
extern int find_src_grp(u_int32_t, u_int32_t, u_int32_t);
|
1995-12-10 13:06:55 +03:00
|
|
|
|
|
|
|
/* kern.c */
|
2002-07-14 20:30:41 +04:00
|
|
|
extern void k_set_rcvbuf(int bufsize);
|
|
|
|
extern void k_hdr_include(int bool);
|
|
|
|
extern void k_set_ttl(int t);
|
|
|
|
extern void k_set_loop(int l);
|
|
|
|
extern void k_set_if(u_int32_t ifa);
|
|
|
|
extern void k_join(u_int32_t grp, u_int32_t ifa);
|
|
|
|
extern void k_leave(u_int32_t grp, u_int32_t ifa);
|
|
|
|
extern void k_init_dvmrp(void);
|
|
|
|
extern void k_stop_dvmrp(void);
|
|
|
|
extern void k_add_vif(vifi_t vifi, struct uvif *v);
|
|
|
|
extern void k_del_vif(vifi_t vifi);
|
|
|
|
extern void k_add_rg(u_int32_t origin, struct gtable *g);
|
|
|
|
extern int k_del_rg(u_int32_t origin, struct gtable *g);
|
|
|
|
extern int k_get_version(void);
|
1995-06-01 06:25:45 +04:00
|
|
|
|
|
|
|
#ifdef SNMP
|
1995-12-10 13:06:55 +03:00
|
|
|
/* prune.c */
|
2002-07-14 20:30:41 +04:00
|
|
|
extern struct rtentry * snmp_find_route();
|
|
|
|
extern struct gtable * find_grp();
|
|
|
|
extern struct stable * find_grp_src();
|
1995-06-01 06:25:45 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef RSRR
|
1995-12-10 13:06:55 +03:00
|
|
|
/* prune.c */
|
1995-06-01 06:25:45 +04:00
|
|
|
extern struct gtable *kernel_table;
|
|
|
|
extern struct gtable *gtp;
|
2002-07-14 20:30:41 +04:00
|
|
|
extern int find_src_grp(u_int32_t src, u_int32_t mask,
|
|
|
|
u_int32_t grp);
|
1995-12-10 13:06:55 +03:00
|
|
|
|
|
|
|
/* rsrr.c */
|
2002-07-14 20:30:41 +04:00
|
|
|
extern void rsrr_init(void);
|
|
|
|
extern void rsrr_read(int f, fd_set *rfd);
|
|
|
|
extern void rsrr_clean(void);
|
|
|
|
extern void rsrr_cache_send(struct gtable *gt, int notify);
|
|
|
|
extern void rsrr_cache_clean(struct gtable *gt);
|
1995-06-01 06:25:45 +04:00
|
|
|
#endif /* RSRR */
|
1997-10-17 14:28:39 +04:00
|
|
|
|
|
|
|
/* vif.c */
|
2002-07-14 20:30:41 +04:00
|
|
|
extern void accept_info_reply(u_int32_t, u_int32_t, u_char *, int);
|
|
|
|
extern void accept_info_request(u_int32_t, u_int32_t,
|
|
|
|
u_char *, int);
|
|
|
|
extern void init_installvifs(void);
|