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