xref: /csrg-svn/libexec/rbootd/defs.h (revision 61443)
155571Sbostic /*
255571Sbostic  * Copyright (c) 1988, 1992 The University of Utah and the Center
355571Sbostic  *	for Software Science (CSS).
4*61443Sbostic  * Copyright (c) 1992, 1993
5*61443Sbostic  *	The Regents of the University of California.  All rights reserved.
655571Sbostic  *
755571Sbostic  * This code is derived from software contributed to Berkeley by
855571Sbostic  * the Center for Software Science of the University of Utah Computer
955571Sbostic  * Science Department.  CSS requests users of this software to return
1055571Sbostic  * to css-dist@cs.utah.edu any improvements that they make and grant
1155571Sbostic  * CSS redistribution rights.
1255571Sbostic  *
1355571Sbostic  * %sccs.include.redist.c%
1455571Sbostic  *
15*61443Sbostic  *	@(#)defs.h	8.1 (Berkeley) 06/04/93
1655571Sbostic  *
1755571Sbostic  * Utah $Hdr: defs.h 3.1 92/07/06$
1855571Sbostic  * Author: Jeff Forys, University of Utah CSS
1955571Sbostic  */
2055571Sbostic 
2155571Sbostic #include "rmp.h"
2255571Sbostic #include "rmp_var.h"
2355571Sbostic 
2455571Sbostic /*
2555571Sbostic **  Common #define's and external variables.  All other files should
2655571Sbostic **  include this.
2755571Sbostic */
2855571Sbostic 
2955571Sbostic /*
3055571Sbostic  *  This may be defined in <sys/param.h>, if not, it's defined here.
3155571Sbostic  */
3255571Sbostic #ifndef	MAXHOSTNAMELEN
3355571Sbostic #define	MAXHOSTNAMELEN 64
3455571Sbostic #endif
3555571Sbostic 
3655571Sbostic /*
3755571Sbostic  *  SIGUSR1 and SIGUSR2 are defined in <signal.h> for 4.3BSD systems.
3855571Sbostic  */
3955571Sbostic #ifndef SIGUSR1
4055571Sbostic #define	SIGUSR1 SIGEMT
4155571Sbostic #endif
4255571Sbostic #ifndef SIGUSR2
4355571Sbostic #define	SIGUSR2 SIGFPE
4455571Sbostic #endif
4555571Sbostic 
4655571Sbostic /*
4755571Sbostic  *  These can be faster & more efficient than strcmp()/strncmp()...
4855571Sbostic  */
4955571Sbostic #define	STREQN(s1,s2)		((*s1 == *s2) && (strcmp(s1,s2) == 0))
5055571Sbostic #define	STRNEQN(s1,s2,n)	((*s1 == *s2) && (strncmp(s1,s2,n) == 0))
5155571Sbostic 
5255571Sbostic /*
5355571Sbostic  *  Configuration file limitations.
5455571Sbostic  */
5555571Sbostic #define	C_MAXFILE	10		/* max number of boot-able files */
5655571Sbostic #define	C_LINELEN	1024		/* max length of line */
5755571Sbostic 
5855571Sbostic /*
5955571Sbostic  *  Direction of packet (used as argument to DispPkt).
6055571Sbostic  */
6155571Sbostic #define	DIR_RCVD	0
6255571Sbostic #define	DIR_SENT	1
6355571Sbostic #define	DIR_NONE	2
6455571Sbostic 
6555571Sbostic /*
6655571Sbostic  *  These need not be functions, so...
6755571Sbostic  */
6855600Sbostic #define	FreeStr(str)	free(str)
6955600Sbostic #define	FreeClient(cli)	free(cli)
7055571Sbostic #define	GenSessID()	(++SessionID ? SessionID: ++SessionID)
7155571Sbostic 
7255571Sbostic /*
7355571Sbostic  *  Converting an Ethernet address to a string is done in many routines.
7455571Sbostic  *  Using `rmp.hp_hdr.saddr' works because this field is *never* changed;
7555571Sbostic  *  it will *always* contain the source address of the packet.
7655571Sbostic  */
7755571Sbostic #define	EnetStr(rptr)	GetEtherAddr(&(rptr)->rmp.hp_hdr.saddr[0])
7855571Sbostic 
7955571Sbostic /*
8055571Sbostic  *  Every machine we can boot will have one of these allocated for it
8155571Sbostic  *  (unless there are no restrictions on who we can boot).
8255571Sbostic  */
8355571Sbostic typedef struct client_s {
8455571Sbostic 	u_char			addr[RMP_ADDRLEN];	/* addr of machine */
8555571Sbostic 	char			*files[C_MAXFILE];	/* boot-able files */
8655571Sbostic 	struct client_s		*next;			/* ptr to next */
8755571Sbostic } CLIENT;
8855571Sbostic 
8955571Sbostic /*
9055571Sbostic  *  Every active connection has one of these allocated for it.
9155571Sbostic  */
9255571Sbostic typedef struct rmpconn_s {
9355571Sbostic 	struct rmp_packet	rmp;			/* RMP packet */
9455571Sbostic 	int			rmplen;			/* length of packet */
9555571Sbostic 	struct timeval		tstamp;			/* last time active */
9655571Sbostic 	int			bootfd;			/* open boot file */
9755571Sbostic 	struct rmpconn_s	*next;			/* ptr to next */
9855571Sbostic } RMPCONN;
9955571Sbostic 
10055571Sbostic /*
10155571Sbostic  *  All these variables are defined in "conf.c".
10255571Sbostic  */
10355571Sbostic extern	char	*ProgName;		/* path-stripped argv[0] */
10455571Sbostic extern	char	MyHost[];		/* this hosts' name */
10555571Sbostic extern	int	MyPid;			/* this processes' ID */
10655571Sbostic extern	int	DebugFlg;		/* set true if debugging */
10755571Sbostic extern	int	BootAny;		/* set true if we can boot anyone */
10855571Sbostic 
10955571Sbostic extern	char	*ConfigFile;		/* configuration file */
11055571Sbostic extern	char	*DfltConfig;		/* default configuration file */
11155571Sbostic extern	char	*DbgFile;		/* debug output file */
11255571Sbostic extern	char	*PidFile;		/* file containing pid of server */
11355571Sbostic extern	char	*BootDir;		/* directory w/boot files */
11455571Sbostic 
11555571Sbostic extern	FILE	*DbgFp;			/* debug file pointer */
11655571Sbostic extern	char	*IntfName;		/* interface we are attached to */
11755571Sbostic 
11855571Sbostic extern	u_short	SessionID;		/* generated session ID */
11955571Sbostic 
12055571Sbostic extern	char	*BootFiles[];		/* list of boot files */
12155571Sbostic 
12255571Sbostic extern	CLIENT	*Clients;		/* list of addrs we'll accept */
12355571Sbostic extern	RMPCONN	*RmpConns;		/* list of active connections */
12455571Sbostic 
12555571Sbostic extern	char	RmpMcastAddr[];		/* RMP multicast address */
12655571Sbostic 
12755600Sbostic void	 AddConn __P((RMPCONN *));
12855600Sbostic int	 BootDone __P((RMPCONN *));
12955600Sbostic void	 BpfClose __P((void));
13055600Sbostic char	*BpfGetIntfName __P((char **));
13155600Sbostic int	 BpfOpen __P((void));
13255600Sbostic int	 BpfRead __P((RMPCONN *, int));
13355600Sbostic int	 BpfWrite __P((RMPCONN *));
13455600Sbostic void	 DebugOff __P((int));
13555600Sbostic void	 DebugOn __P((int));
13655600Sbostic void	 DispPkt __P((RMPCONN *, int));
13755600Sbostic void	 DoTimeout __P((void));
13855600Sbostic void	 DspFlnm __P((u_int, char *));
13955600Sbostic void	 Exit __P((int));
14055600Sbostic CLIENT	*FindClient __P((RMPCONN *));
14155600Sbostic RMPCONN	*FindConn __P((RMPCONN *));
14255600Sbostic void	 FreeClients __P((void));
14355600Sbostic void	 FreeConn __P((RMPCONN *));
14455600Sbostic void	 FreeConns __P((void));
14555600Sbostic int	 GetBootFiles __P((void));
14655600Sbostic char	*GetEtherAddr __P((u_char *));
14755600Sbostic CLIENT	*NewClient __P((u_char *));
14855600Sbostic RMPCONN	*NewConn __P((RMPCONN *));
14955600Sbostic char	*NewStr __P((char *));
15055600Sbostic u_char	*ParseAddr __P((char *));
15155600Sbostic int	 ParseConfig __P((void));
15255600Sbostic void	 ProcessPacket __P((RMPCONN *, CLIENT *));
15355600Sbostic void	 ReConfig __P((int));
15455600Sbostic void	 RemoveConn __P((RMPCONN *));
15555600Sbostic int	 SendBootRepl __P((struct rmp_packet *, RMPCONN *, char *[]));
15655600Sbostic int	 SendFileNo __P((struct rmp_packet *, RMPCONN *, char *[]));
15755600Sbostic int	 SendPacket __P((RMPCONN *));
15855600Sbostic int	 SendReadRepl __P((RMPCONN *));
15955600Sbostic int	 SendServerID __P((RMPCONN *));
160