defs.h revision 330897
1/*- 2 * SPDX-License-Identifier: BSD-3-Clause 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@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 * $FreeBSD: stable/11/libexec/rbootd/defs.h 330897 2018-03-14 03:19:51Z eadler $ 45 */ 46 47#include "rmp.h" 48#include "rmp_var.h" 49 50/* 51** Common #define's and external variables. All other files should 52** include this. 53*/ 54 55/* 56 * This may be defined in <sys/param.h>, if not, it's defined here. 57 */ 58#ifndef MAXHOSTNAMELEN 59#define MAXHOSTNAMELEN 256 60#endif 61 62/* 63 * SIGUSR1 and SIGUSR2 are defined in <signal.h> for 4.3BSD systems. 64 */ 65#ifndef SIGUSR1 66#define SIGUSR1 SIGEMT 67#endif 68#ifndef SIGUSR2 69#define SIGUSR2 SIGFPE 70#endif 71 72/* 73 * These can be faster & more efficient than strcmp()/strncmp()... 74 */ 75#define STREQN(s1,s2) ((*s1 == *s2) && (strcmp(s1,s2) == 0)) 76#define STRNEQN(s1,s2,n) ((*s1 == *s2) && (strncmp(s1,s2,n) == 0)) 77 78/* 79 * Configuration file limitations. 80 */ 81#define C_MAXFILE 10 /* max number of boot-able files */ 82#define C_LINELEN 1024 /* max length of line */ 83 84/* 85 * Direction of packet (used as argument to DispPkt). 86 */ 87#define DIR_RCVD 0 88#define DIR_SENT 1 89#define DIR_NONE 2 90 91/* 92 * These need not be functions, so... 93 */ 94#define FreeStr(str) free(str) 95#define FreeClient(cli) free(cli) 96#define GenSessID() (++SessionID ? SessionID: ++SessionID) 97 98/* 99 * Converting an Ethernet address to a string is done in many routines. 100 * Using `rmp.hp_hdr.saddr' works because this field is *never* changed; 101 * it will *always* contain the source address of the packet. 102 */ 103#define EnetStr(rptr) GetEtherAddr(&(rptr)->rmp.hp_hdr.saddr[0]) 104 105/* 106 * Every machine we can boot will have one of these allocated for it 107 * (unless there are no restrictions on who we can boot). 108 */ 109typedef struct client_s { 110 u_int8_t addr[RMP_ADDRLEN]; /* addr of machine */ 111 char *files[C_MAXFILE]; /* boot-able files */ 112 struct client_s *next; /* ptr to next */ 113} CLIENT; 114 115/* 116 * Every active connection has one of these allocated for it. 117 */ 118typedef struct rmpconn_s { 119 struct rmp_packet rmp; /* RMP packet */ 120 int rmplen; /* length of packet */ 121 struct timeval tstamp; /* last time active */ 122 int bootfd; /* open boot file */ 123 struct rmpconn_s *next; /* ptr to next */ 124} RMPCONN; 125 126/* 127 * All these variables are defined in "conf.c". 128 */ 129extern char MyHost[]; /* this hosts' name */ 130extern pid_t MyPid; /* this processes' ID */ 131extern int DebugFlg; /* set true if debugging */ 132extern int BootAny; /* set true if we can boot anyone */ 133 134extern char *ConfigFile; /* configuration file */ 135extern char *DfltConfig; /* default configuration file */ 136extern char *DbgFile; /* debug output file */ 137extern char *PidFile; /* file containing pid of server */ 138extern char *BootDir; /* directory w/boot files */ 139 140extern FILE *DbgFp; /* debug file pointer */ 141extern char *IntfName; /* interface we are attached to */ 142 143extern u_int16_t SessionID; /* generated session ID */ 144 145extern char *BootFiles[]; /* list of boot files */ 146 147extern CLIENT *Clients; /* list of addrs we'll accept */ 148extern RMPCONN *RmpConns; /* list of active connections */ 149 150extern u_int8_t RmpMcastAddr[]; /* RMP multicast address */ 151 152void AddConn(RMPCONN *); 153int BootDone(RMPCONN *); 154void BpfClose(void); 155char *BpfGetIntfName(char **); 156int BpfOpen(void); 157int BpfRead(RMPCONN *, int); 158int BpfWrite(RMPCONN *); 159void DebugOff(int); 160void DebugOn(int); 161void DispPkt(RMPCONN *, int); 162void DoTimeout(void); 163void DspFlnm(u_int, char *); 164void Exit(int); 165CLIENT *FindClient(RMPCONN *); 166RMPCONN *FindConn(RMPCONN *); 167void FreeClients(void); 168void FreeConn(RMPCONN *); 169void FreeConns(void); 170int GetBootFiles(void); 171char *GetEtherAddr(u_int8_t *); 172CLIENT *NewClient(u_int8_t *); 173RMPCONN *NewConn(RMPCONN *); 174char *NewStr(char *); 175u_int8_t *ParseAddr(char *); 176int ParseConfig(void); 177void ProcessPacket(RMPCONN *, CLIENT *); 178void ReConfig(int); 179void RemoveConn(RMPCONN *); 180int SendBootRepl(struct rmp_packet *, RMPCONN *, char *[]); 181int SendFileNo(struct rmp_packet *, RMPCONN *, char *[]); 182int SendPacket(RMPCONN *); 183int SendReadRepl(RMPCONN *); 184int SendServerID(RMPCONN *); 185