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