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