/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1988, 1992 The University of Utah and the Center4* for Software Science (CSS).5* Copyright (c) 1992, 19936* The Regents of the University of California. All rights reserved.7*8* This code is derived from software contributed to Berkeley by9* the Center for Software Science of the University of Utah Computer10* Science Department. CSS requests users of this software to return11* to [email protected] any improvements that they make and grant12* CSS redistribution rights.13*14* Redistribution and use in source and binary forms, with or without15* modification, are permitted provided that the following conditions16* are met:17* 1. Redistributions of source code must retain the above copyright18* notice, this list of conditions and the following disclaimer.19* 2. Redistributions in binary form must reproduce the above copyright20* notice, this list of conditions and the following disclaimer in the21* documentation and/or other materials provided with the distribution.22* 3. Neither the name of the University nor the names of its contributors23* may be used to endorse or promote products derived from this software24* without specific prior written permission.25*26* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND27* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE28* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE29* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE30* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL31* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS32* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)33* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT34* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY35* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF36* SUCH DAMAGE.37*38* From: Utah Hdr: defs.h 3.1 92/07/0639* Author: Jeff Forys, University of Utah CSS40*/4142#include "rmp.h"43#include "rmp_var.h"4445/*46** Common #define's and external variables. All other files should47** include this.48*/4950/*51* This may be defined in <sys/param.h>, if not, it's defined here.52*/53#ifndef MAXHOSTNAMELEN54#define MAXHOSTNAMELEN 25655#endif5657/*58* SIGUSR1 and SIGUSR2 are defined in <signal.h> for 4.3BSD systems.59*/60#ifndef SIGUSR161#define SIGUSR1 SIGEMT62#endif63#ifndef SIGUSR264#define SIGUSR2 SIGFPE65#endif6667/*68* These can be faster & more efficient than strcmp()/strncmp()...69*/70#define STREQN(s1,s2) ((*s1 == *s2) && (strcmp(s1,s2) == 0))71#define STRNEQN(s1,s2,n) ((*s1 == *s2) && (strncmp(s1,s2,n) == 0))7273/*74* Configuration file limitations.75*/76#define C_MAXFILE 10 /* max number of boot-able files */77#define C_LINELEN 1024 /* max length of line */7879/*80* Direction of packet (used as argument to DispPkt).81*/82#define DIR_RCVD 083#define DIR_SENT 184#define DIR_NONE 28586/*87* These need not be functions, so...88*/89#define FreeStr(str) free(str)90#define FreeClient(cli) free(cli)91#define GenSessID() (++SessionID ? SessionID: ++SessionID)9293/*94* Converting an Ethernet address to a string is done in many routines.95* Using `rmp.hp_hdr.saddr' works because this field is *never* changed;96* it will *always* contain the source address of the packet.97*/98#define EnetStr(rptr) GetEtherAddr(&(rptr)->rmp.hp_hdr.saddr[0])99100/*101* Every machine we can boot will have one of these allocated for it102* (unless there are no restrictions on who we can boot).103*/104typedef struct client_s {105u_int8_t addr[RMP_ADDRLEN]; /* addr of machine */106char *files[C_MAXFILE]; /* boot-able files */107struct client_s *next; /* ptr to next */108} CLIENT;109110/*111* Every active connection has one of these allocated for it.112*/113typedef struct rmpconn_s {114struct rmp_packet rmp; /* RMP packet */115int rmplen; /* length of packet */116struct timeval tstamp; /* last time active */117int bootfd; /* open boot file */118struct rmpconn_s *next; /* ptr to next */119} RMPCONN;120121/*122* All these variables are defined in "conf.c".123*/124extern char MyHost[]; /* this hosts' name */125extern pid_t MyPid; /* this processes' ID */126extern int DebugFlg; /* set true if debugging */127extern int BootAny; /* set true if we can boot anyone */128129extern char *ConfigFile; /* configuration file */130extern char *DfltConfig; /* default configuration file */131extern char *DbgFile; /* debug output file */132extern char *PidFile; /* file containing pid of server */133extern char *BootDir; /* directory w/boot files */134135extern FILE *DbgFp; /* debug file pointer */136extern char *IntfName; /* interface we are attached to */137138extern u_int16_t SessionID; /* generated session ID */139140extern char *BootFiles[]; /* list of boot files */141142extern CLIENT *Clients; /* list of addrs we'll accept */143extern RMPCONN *RmpConns; /* list of active connections */144145extern u_int8_t RmpMcastAddr[]; /* RMP multicast address */146147void AddConn(RMPCONN *);148int BootDone(RMPCONN *);149void BpfClose(void);150char *BpfGetIntfName(char **);151int BpfOpen(void);152int BpfRead(RMPCONN *, int);153int BpfWrite(RMPCONN *);154void DebugOff(int);155void DebugOn(int);156void DispPkt(RMPCONN *, int);157void DoTimeout(void);158void DspFlnm(u_int, char *);159void Exit(int);160CLIENT *FindClient(RMPCONN *);161RMPCONN *FindConn(RMPCONN *);162void FreeClients(void);163void FreeConn(RMPCONN *);164void FreeConns(void);165int GetBootFiles(void);166char *GetEtherAddr(u_int8_t *);167CLIENT *NewClient(u_int8_t *);168RMPCONN *NewConn(RMPCONN *);169char *NewStr(char *);170u_int8_t *ParseAddr(char *);171int ParseConfig(void);172void ProcessPacket(RMPCONN *, CLIENT *);173void ReConfig(int);174void RemoveConn(RMPCONN *);175int SendBootRepl(struct rmp_packet *, RMPCONN *, char *[]);176int SendFileNo(struct rmp_packet *, RMPCONN *, char *[]);177int SendPacket(RMPCONN *);178int SendReadRepl(RMPCONN *);179int SendServerID(RMPCONN *);180181182