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