xref: /original-bsd/libexec/rbootd/defs.h (revision c3e32dec)
1 /*
2  * Copyright (c) 1988, 1992 The University of Utah and the Center
3  *	for Software Science (CSS).
4  * Copyright (c) 1992, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * the Center for Software Science of the University of Utah Computer
9  * Science Department.  CSS requests users of this software to return
10  * to css-dist@cs.utah.edu any improvements that they make and grant
11  * CSS redistribution rights.
12  *
13  * %sccs.include.redist.c%
14  *
15  *	@(#)defs.h	8.1 (Berkeley) 06/04/93
16  *
17  * Utah $Hdr: defs.h 3.1 92/07/06$
18  * Author: Jeff Forys, University of Utah CSS
19  */
20 
21 #include "rmp.h"
22 #include "rmp_var.h"
23 
24 /*
25 **  Common #define's and external variables.  All other files should
26 **  include this.
27 */
28 
29 /*
30  *  This may be defined in <sys/param.h>, if not, it's defined here.
31  */
32 #ifndef	MAXHOSTNAMELEN
33 #define	MAXHOSTNAMELEN 64
34 #endif
35 
36 /*
37  *  SIGUSR1 and SIGUSR2 are defined in <signal.h> for 4.3BSD systems.
38  */
39 #ifndef SIGUSR1
40 #define	SIGUSR1 SIGEMT
41 #endif
42 #ifndef SIGUSR2
43 #define	SIGUSR2 SIGFPE
44 #endif
45 
46 /*
47  *  These can be faster & more efficient than strcmp()/strncmp()...
48  */
49 #define	STREQN(s1,s2)		((*s1 == *s2) && (strcmp(s1,s2) == 0))
50 #define	STRNEQN(s1,s2,n)	((*s1 == *s2) && (strncmp(s1,s2,n) == 0))
51 
52 /*
53  *  Configuration file limitations.
54  */
55 #define	C_MAXFILE	10		/* max number of boot-able files */
56 #define	C_LINELEN	1024		/* max length of line */
57 
58 /*
59  *  Direction of packet (used as argument to DispPkt).
60  */
61 #define	DIR_RCVD	0
62 #define	DIR_SENT	1
63 #define	DIR_NONE	2
64 
65 /*
66  *  These need not be functions, so...
67  */
68 #define	FreeStr(str)	free(str)
69 #define	FreeClient(cli)	free(cli)
70 #define	GenSessID()	(++SessionID ? SessionID: ++SessionID)
71 
72 /*
73  *  Converting an Ethernet address to a string is done in many routines.
74  *  Using `rmp.hp_hdr.saddr' works because this field is *never* changed;
75  *  it will *always* contain the source address of the packet.
76  */
77 #define	EnetStr(rptr)	GetEtherAddr(&(rptr)->rmp.hp_hdr.saddr[0])
78 
79 /*
80  *  Every machine we can boot will have one of these allocated for it
81  *  (unless there are no restrictions on who we can boot).
82  */
83 typedef struct client_s {
84 	u_char			addr[RMP_ADDRLEN];	/* addr of machine */
85 	char			*files[C_MAXFILE];	/* boot-able files */
86 	struct client_s		*next;			/* ptr to next */
87 } CLIENT;
88 
89 /*
90  *  Every active connection has one of these allocated for it.
91  */
92 typedef struct rmpconn_s {
93 	struct rmp_packet	rmp;			/* RMP packet */
94 	int			rmplen;			/* length of packet */
95 	struct timeval		tstamp;			/* last time active */
96 	int			bootfd;			/* open boot file */
97 	struct rmpconn_s	*next;			/* ptr to next */
98 } RMPCONN;
99 
100 /*
101  *  All these variables are defined in "conf.c".
102  */
103 extern	char	*ProgName;		/* path-stripped argv[0] */
104 extern	char	MyHost[];		/* this hosts' name */
105 extern	int	MyPid;			/* this processes' ID */
106 extern	int	DebugFlg;		/* set true if debugging */
107 extern	int	BootAny;		/* set true if we can boot anyone */
108 
109 extern	char	*ConfigFile;		/* configuration file */
110 extern	char	*DfltConfig;		/* default configuration file */
111 extern	char	*DbgFile;		/* debug output file */
112 extern	char	*PidFile;		/* file containing pid of server */
113 extern	char	*BootDir;		/* directory w/boot files */
114 
115 extern	FILE	*DbgFp;			/* debug file pointer */
116 extern	char	*IntfName;		/* interface we are attached to */
117 
118 extern	u_short	SessionID;		/* generated session ID */
119 
120 extern	char	*BootFiles[];		/* list of boot files */
121 
122 extern	CLIENT	*Clients;		/* list of addrs we'll accept */
123 extern	RMPCONN	*RmpConns;		/* list of active connections */
124 
125 extern	char	RmpMcastAddr[];		/* RMP multicast address */
126 
127 void	 AddConn __P((RMPCONN *));
128 int	 BootDone __P((RMPCONN *));
129 void	 BpfClose __P((void));
130 char	*BpfGetIntfName __P((char **));
131 int	 BpfOpen __P((void));
132 int	 BpfRead __P((RMPCONN *, int));
133 int	 BpfWrite __P((RMPCONN *));
134 void	 DebugOff __P((int));
135 void	 DebugOn __P((int));
136 void	 DispPkt __P((RMPCONN *, int));
137 void	 DoTimeout __P((void));
138 void	 DspFlnm __P((u_int, char *));
139 void	 Exit __P((int));
140 CLIENT	*FindClient __P((RMPCONN *));
141 RMPCONN	*FindConn __P((RMPCONN *));
142 void	 FreeClients __P((void));
143 void	 FreeConn __P((RMPCONN *));
144 void	 FreeConns __P((void));
145 int	 GetBootFiles __P((void));
146 char	*GetEtherAddr __P((u_char *));
147 CLIENT	*NewClient __P((u_char *));
148 RMPCONN	*NewConn __P((RMPCONN *));
149 char	*NewStr __P((char *));
150 u_char	*ParseAddr __P((char *));
151 int	 ParseConfig __P((void));
152 void	 ProcessPacket __P((RMPCONN *, CLIENT *));
153 void	 ReConfig __P((int));
154 void	 RemoveConn __P((RMPCONN *));
155 int	 SendBootRepl __P((struct rmp_packet *, RMPCONN *, char *[]));
156 int	 SendFileNo __P((struct rmp_packet *, RMPCONN *, char *[]));
157 int	 SendPacket __P((RMPCONN *));
158 int	 SendReadRepl __P((RMPCONN *));
159 int	 SendServerID __P((RMPCONN *));
160