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