xref: /openbsd/usr.sbin/rbootd/defs.h (revision db3296cf)
1 /*	$OpenBSD: defs.h,v 1.6 2003/06/02 23:36:54 millert Exp $	*/
2 /*	$NetBSD: defs.h,v 1.5 1995/10/06 05:12:14 thorpej Exp $	*/
3 
4 /*
5  * Copyright (c) 1988, 1992 The University of Utah and the Center
6  *	for Software Science (CSS).
7  * Copyright (c) 1992, 1993
8  *	The Regents of the University of California.  All rights reserved.
9  *
10  * This code is derived from software contributed to Berkeley by
11  * the Center for Software Science of the University of Utah Computer
12  * Science Department.  CSS requests users of this software to return
13  * to css-dist@cs.utah.edu any improvements that they make and grant
14  * CSS redistribution rights.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  * 3. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  *	from: @(#)defs.h	8.1 (Berkeley) 6/4/93
41  *
42  * From: Utah Hdr: defs.h 3.1 92/07/06
43  * Author: Jeff Forys, University of Utah CSS
44  */
45 
46 #include "rmp.h"
47 #include "rmp_var.h"
48 
49 /*
50 **  Common #define's and external variables.  All other files should
51 **  include this.
52 */
53 
54 /*
55  *  This may be defined in <sys/param.h>, if not, it's defined here.
56  */
57 #ifndef	MAXHOSTNAMELEN
58 #define	MAXHOSTNAMELEN 64
59 #endif
60 
61 /*
62  *  SIGUSR1 and SIGUSR2 are defined in <signal.h> for 4.3BSD systems.
63  */
64 #ifndef SIGUSR1
65 #define	SIGUSR1 SIGEMT
66 #endif
67 #ifndef SIGUSR2
68 #define	SIGUSR2 SIGFPE
69 #endif
70 
71 /*
72  *  These can be faster & more efficient than strcmp()/strncmp()...
73  */
74 #define	STREQN(s1,s2)		((*s1 == *s2) && (strcmp(s1,s2) == 0))
75 #define	STRNEQN(s1,s2,n)	((*s1 == *s2) && (strncmp(s1,s2,n) == 0))
76 
77 /*
78  *  Configuration file limitations.
79  */
80 #define	C_MAXFILE	10		/* max number of boot-able files */
81 #define	C_LINELEN	1024		/* max length of line */
82 
83 /*
84  *  Direction of packet (used as argument to DispPkt).
85  */
86 #define	DIR_RCVD	0
87 #define	DIR_SENT	1
88 #define	DIR_NONE	2
89 
90 /*
91  *  These need not be functions, so...
92  */
93 #define	FreeStr(str)	free(str)
94 #define	FreeClient(cli)	free(cli)
95 #define	GenSessID()	(++SessionID ? SessionID: ++SessionID)
96 
97 /*
98  *  Converting an Ethernet address to a string is done in many routines.
99  *  Using `rmp.hp_hdr.saddr' works because this field is *never* changed;
100  *  it will *always* contain the source address of the packet.
101  */
102 #define	EnetStr(rptr)	GetEtherAddr(&(rptr)->rmp.hp_hdr.saddr[0])
103 
104 /*
105  *  Every machine we can boot will have one of these allocated for it
106  *  (unless there are no restrictions on who we can boot).
107  */
108 typedef struct client_s {
109 	u_int8_t		addr[RMP_ADDRLEN];	/* addr of machine */
110 	char			*files[C_MAXFILE];	/* boot-able files */
111 	struct client_s		*next;			/* ptr to next */
112 } CLIENT;
113 
114 /*
115  *  Every active connection has one of these allocated for it.
116  */
117 typedef struct rmpconn_s {
118 	struct rmp_packet	rmp;			/* RMP packet */
119 	int			rmplen;			/* length of packet */
120 	struct timeval		tstamp;			/* last time active */
121 	int			bootfd;			/* open boot file */
122 	struct rmpconn_s	*next;			/* ptr to next */
123 } RMPCONN;
124 
125 /*
126  *  All these variables are defined in "conf.c".
127  */
128 extern	char	MyHost[];		/* this hosts' name */
129 extern	int	DebugFlg;		/* set true if debugging */
130 extern	int	BootAny;		/* set true if we can boot anyone */
131 
132 extern	char	*ConfigFile;		/* configuration file */
133 extern	char	*DfltConfig;		/* default configuration file */
134 extern	char	*DbgFile;		/* debug output file */
135 extern	char	*BootDir;		/* directory w/boot files */
136 
137 extern	FILE	*DbgFp;			/* debug file pointer */
138 extern	char	*IntfName;		/* interface we are attached to */
139 
140 extern	u_int16_t SessionID;		/* generated session ID */
141 
142 extern	char	*BootFiles[];		/* list of boot files */
143 
144 extern	CLIENT	*Clients;		/* list of addrs we'll accept */
145 extern	RMPCONN	*RmpConns;		/* list of active connections */
146 
147 extern	u_int8_t RmpMcastAddr[];	/* RMP multicast address */
148 
149 void	 AddConn(RMPCONN *);
150 int	 BootDone(RMPCONN *);
151 char	*BpfGetIntfName(char **);
152 int	 BpfOpen(void);
153 int	 BpfRead(RMPCONN *, int);
154 int	 BpfWrite(RMPCONN *);
155 void	 DispPkt(RMPCONN *, int);
156 void	 DoExit(void);
157 void	 DspFlnm(u_int, char *);
158 RMPCONN	*FindConn(RMPCONN *);
159 void	 FreeClients(void);
160 void	 FreeConn(RMPCONN *);
161 void	 FreeConns(void);
162 int	 GetBootFiles(void);
163 char	*GetEtherAddr(u_int8_t *);
164 CLIENT	*NewClient(u_int8_t *);
165 RMPCONN	*NewConn(RMPCONN *);
166 char	*NewStr(char *);
167 u_int8_t *ParseAddr(char *);
168 int	 ParseConfig(void);
169 void	 ProcessPacket(RMPCONN *, CLIENT *);
170 void	 RemoveConn(RMPCONN *);
171 int	 SendBootRepl(struct rmp_packet *, RMPCONN *, char *[]);
172 int	 SendFileNo(struct rmp_packet *, RMPCONN *, char *[]);
173 int	 SendPacket(RMPCONN *);
174 int	 SendReadRepl(RMPCONN *);
175 int	 SendServerID(RMPCONN *);
176