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