xref: /freebsd/libexec/rbootd/defs.h (revision 43581d7b6617959e4452094d9330ef020034a6c9)
1*8a16b7a1SPedro F. Giffuni /*-
2*8a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*8a16b7a1SPedro F. Giffuni  *
40559b331SSteve Price  * Copyright (c) 1988, 1992 The University of Utah and the Center
50559b331SSteve Price  *	for Software Science (CSS).
60559b331SSteve Price  * Copyright (c) 1992, 1993
70559b331SSteve Price  *	The Regents of the University of California.  All rights reserved.
80559b331SSteve Price  *
90559b331SSteve Price  * This code is derived from software contributed to Berkeley by
100559b331SSteve Price  * the Center for Software Science of the University of Utah Computer
110559b331SSteve Price  * Science Department.  CSS requests users of this software to return
120559b331SSteve Price  * to css-dist@cs.utah.edu any improvements that they make and grant
130559b331SSteve Price  * CSS redistribution rights.
140559b331SSteve Price  *
150559b331SSteve Price  * Redistribution and use in source and binary forms, with or without
160559b331SSteve Price  * modification, are permitted provided that the following conditions
170559b331SSteve Price  * are met:
180559b331SSteve Price  * 1. Redistributions of source code must retain the above copyright
190559b331SSteve Price  *    notice, this list of conditions and the following disclaimer.
200559b331SSteve Price  * 2. Redistributions in binary form must reproduce the above copyright
210559b331SSteve Price  *    notice, this list of conditions and the following disclaimer in the
220559b331SSteve Price  *    documentation and/or other materials provided with the distribution.
235efaea4cSChristian Brueffer  * 3. Neither the name of the University nor the names of its contributors
240559b331SSteve Price  *    may be used to endorse or promote products derived from this software
250559b331SSteve Price  *    without specific prior written permission.
260559b331SSteve Price  *
270559b331SSteve Price  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
280559b331SSteve Price  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
290559b331SSteve Price  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
300559b331SSteve Price  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
310559b331SSteve Price  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
320559b331SSteve Price  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
330559b331SSteve Price  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
340559b331SSteve Price  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
350559b331SSteve Price  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
360559b331SSteve Price  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
370559b331SSteve Price  * SUCH DAMAGE.
380559b331SSteve Price  *
390559b331SSteve Price  * From: Utah Hdr: defs.h 3.1 92/07/06
400559b331SSteve Price  * Author: Jeff Forys, University of Utah CSS
410559b331SSteve Price  */
420559b331SSteve Price 
430559b331SSteve Price #include "rmp.h"
440559b331SSteve Price #include "rmp_var.h"
450559b331SSteve Price 
460559b331SSteve Price /*
470559b331SSteve Price **  Common #define's and external variables.  All other files should
480559b331SSteve Price **  include this.
490559b331SSteve Price */
500559b331SSteve Price 
510559b331SSteve Price /*
520559b331SSteve Price  *  This may be defined in <sys/param.h>, if not, it's defined here.
530559b331SSteve Price  */
540559b331SSteve Price #ifndef	MAXHOSTNAMELEN
5597ad2a1bSKris Kennaway #define	MAXHOSTNAMELEN 256
560559b331SSteve Price #endif
570559b331SSteve Price 
580559b331SSteve Price /*
590559b331SSteve Price  *  SIGUSR1 and SIGUSR2 are defined in <signal.h> for 4.3BSD systems.
600559b331SSteve Price  */
610559b331SSteve Price #ifndef SIGUSR1
620559b331SSteve Price #define	SIGUSR1 SIGEMT
630559b331SSteve Price #endif
640559b331SSteve Price #ifndef SIGUSR2
650559b331SSteve Price #define	SIGUSR2 SIGFPE
660559b331SSteve Price #endif
670559b331SSteve Price 
680559b331SSteve Price /*
690559b331SSteve Price  *  These can be faster & more efficient than strcmp()/strncmp()...
700559b331SSteve Price  */
710559b331SSteve Price #define	STREQN(s1,s2)		((*s1 == *s2) && (strcmp(s1,s2) == 0))
720559b331SSteve Price #define	STRNEQN(s1,s2,n)	((*s1 == *s2) && (strncmp(s1,s2,n) == 0))
730559b331SSteve Price 
740559b331SSteve Price /*
750559b331SSteve Price  *  Configuration file limitations.
760559b331SSteve Price  */
770559b331SSteve Price #define	C_MAXFILE	10		/* max number of boot-able files */
780559b331SSteve Price #define	C_LINELEN	1024		/* max length of line */
790559b331SSteve Price 
800559b331SSteve Price /*
810559b331SSteve Price  *  Direction of packet (used as argument to DispPkt).
820559b331SSteve Price  */
830559b331SSteve Price #define	DIR_RCVD	0
840559b331SSteve Price #define	DIR_SENT	1
850559b331SSteve Price #define	DIR_NONE	2
860559b331SSteve Price 
870559b331SSteve Price /*
880559b331SSteve Price  *  These need not be functions, so...
890559b331SSteve Price  */
900559b331SSteve Price #define	FreeStr(str)	free(str)
910559b331SSteve Price #define	FreeClient(cli)	free(cli)
920559b331SSteve Price #define	GenSessID()	(++SessionID ? SessionID: ++SessionID)
930559b331SSteve Price 
940559b331SSteve Price /*
950559b331SSteve Price  *  Converting an Ethernet address to a string is done in many routines.
960559b331SSteve Price  *  Using `rmp.hp_hdr.saddr' works because this field is *never* changed;
970559b331SSteve Price  *  it will *always* contain the source address of the packet.
980559b331SSteve Price  */
990559b331SSteve Price #define	EnetStr(rptr)	GetEtherAddr(&(rptr)->rmp.hp_hdr.saddr[0])
1000559b331SSteve Price 
1010559b331SSteve Price /*
1020559b331SSteve Price  *  Every machine we can boot will have one of these allocated for it
1030559b331SSteve Price  *  (unless there are no restrictions on who we can boot).
1040559b331SSteve Price  */
1050559b331SSteve Price typedef struct client_s {
1060559b331SSteve Price 	u_int8_t		addr[RMP_ADDRLEN];	/* addr of machine */
1070559b331SSteve Price 	char			*files[C_MAXFILE];	/* boot-able files */
1080559b331SSteve Price 	struct client_s		*next;			/* ptr to next */
1090559b331SSteve Price } CLIENT;
1100559b331SSteve Price 
1110559b331SSteve Price /*
1120559b331SSteve Price  *  Every active connection has one of these allocated for it.
1130559b331SSteve Price  */
1140559b331SSteve Price typedef struct rmpconn_s {
1150559b331SSteve Price 	struct rmp_packet	rmp;			/* RMP packet */
1160559b331SSteve Price 	int			rmplen;			/* length of packet */
1170559b331SSteve Price 	struct timeval		tstamp;			/* last time active */
1180559b331SSteve Price 	int			bootfd;			/* open boot file */
1190559b331SSteve Price 	struct rmpconn_s	*next;			/* ptr to next */
1200559b331SSteve Price } RMPCONN;
1210559b331SSteve Price 
1220559b331SSteve Price /*
1230559b331SSteve Price  *  All these variables are defined in "conf.c".
1240559b331SSteve Price  */
1250559b331SSteve Price extern	char	MyHost[];		/* this hosts' name */
1260559b331SSteve Price extern	pid_t	MyPid;			/* this processes' ID */
1270559b331SSteve Price extern	int	DebugFlg;		/* set true if debugging */
1280559b331SSteve Price extern	int	BootAny;		/* set true if we can boot anyone */
1290559b331SSteve Price 
1300559b331SSteve Price extern	char	*ConfigFile;		/* configuration file */
1310559b331SSteve Price extern	char	*DfltConfig;		/* default configuration file */
1320559b331SSteve Price extern	char	*DbgFile;		/* debug output file */
1330559b331SSteve Price extern	char	*PidFile;		/* file containing pid of server */
1340559b331SSteve Price extern	char	*BootDir;		/* directory w/boot files */
1350559b331SSteve Price 
1360559b331SSteve Price extern	FILE	*DbgFp;			/* debug file pointer */
1370559b331SSteve Price extern	char	*IntfName;		/* interface we are attached to */
1380559b331SSteve Price 
1390559b331SSteve Price extern	u_int16_t SessionID;		/* generated session ID */
1400559b331SSteve Price 
1410559b331SSteve Price extern	char	*BootFiles[];		/* list of boot files */
1420559b331SSteve Price 
1430559b331SSteve Price extern	CLIENT	*Clients;		/* list of addrs we'll accept */
1440559b331SSteve Price extern	RMPCONN	*RmpConns;		/* list of active connections */
1450559b331SSteve Price 
1460559b331SSteve Price extern	u_int8_t RmpMcastAddr[];	/* RMP multicast address */
1470559b331SSteve Price 
148266ebcd3SWarner Losh void	 AddConn(RMPCONN *);
149266ebcd3SWarner Losh int	 BootDone(RMPCONN *);
150266ebcd3SWarner Losh void	 BpfClose(void);
151266ebcd3SWarner Losh char	*BpfGetIntfName(char **);
152266ebcd3SWarner Losh int	 BpfOpen(void);
153266ebcd3SWarner Losh int	 BpfRead(RMPCONN *, int);
154266ebcd3SWarner Losh int	 BpfWrite(RMPCONN *);
155266ebcd3SWarner Losh void	 DebugOff(int);
156266ebcd3SWarner Losh void	 DebugOn(int);
157266ebcd3SWarner Losh void	 DispPkt(RMPCONN *, int);
158266ebcd3SWarner Losh void	 DoTimeout(void);
159266ebcd3SWarner Losh void	 DspFlnm(u_int, char *);
160266ebcd3SWarner Losh void	 Exit(int);
161266ebcd3SWarner Losh CLIENT	*FindClient(RMPCONN *);
162266ebcd3SWarner Losh RMPCONN	*FindConn(RMPCONN *);
163266ebcd3SWarner Losh void	 FreeClients(void);
164266ebcd3SWarner Losh void	 FreeConn(RMPCONN *);
165266ebcd3SWarner Losh void	 FreeConns(void);
166266ebcd3SWarner Losh int	 GetBootFiles(void);
167266ebcd3SWarner Losh char	*GetEtherAddr(u_int8_t *);
168266ebcd3SWarner Losh CLIENT	*NewClient(u_int8_t *);
169266ebcd3SWarner Losh RMPCONN	*NewConn(RMPCONN *);
170266ebcd3SWarner Losh char	*NewStr(char *);
171266ebcd3SWarner Losh u_int8_t *ParseAddr(char *);
172266ebcd3SWarner Losh int	 ParseConfig(void);
173266ebcd3SWarner Losh void	 ProcessPacket(RMPCONN *, CLIENT *);
174266ebcd3SWarner Losh void	 ReConfig(int);
175266ebcd3SWarner Losh void	 RemoveConn(RMPCONN *);
176266ebcd3SWarner Losh int	 SendBootRepl(struct rmp_packet *, RMPCONN *, char *[]);
177266ebcd3SWarner Losh int	 SendFileNo(struct rmp_packet *, RMPCONN *, char *[]);
178266ebcd3SWarner Losh int	 SendPacket(RMPCONN *);
179266ebcd3SWarner Losh int	 SendReadRepl(RMPCONN *);
180266ebcd3SWarner Losh int	 SendServerID(RMPCONN *);
181