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