1331722Seadler/* 21592Srgrimes * Copyright (c) 1988, 1992 The University of Utah and the Center 31592Srgrimes * for Software Science (CSS). 41592Srgrimes * Copyright (c) 1992, 1993 51592Srgrimes * The Regents of the University of California. All rights reserved. 61592Srgrimes * 71592Srgrimes * This code is derived from software contributed to Berkeley by 81592Srgrimes * the Center for Software Science of the University of Utah Computer 91592Srgrimes * Science Department. CSS requests users of this software to return 101592Srgrimes * to css-dist@cs.utah.edu any improvements that they make and grant 111592Srgrimes * CSS redistribution rights. 121592Srgrimes * 131592Srgrimes * Redistribution and use in source and binary forms, with or without 141592Srgrimes * modification, are permitted provided that the following conditions 151592Srgrimes * are met: 161592Srgrimes * 1. Redistributions of source code must retain the above copyright 171592Srgrimes * notice, this list of conditions and the following disclaimer. 181592Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 191592Srgrimes * notice, this list of conditions and the following disclaimer in the 201592Srgrimes * documentation and/or other materials provided with the distribution. 21262136Sbrueffer * 3. Neither the name of the University nor the names of its contributors 221592Srgrimes * may be used to endorse or promote products derived from this software 231592Srgrimes * without specific prior written permission. 241592Srgrimes * 251592Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 261592Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 271592Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 281592Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 291592Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 301592Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 311592Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 321592Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 331592Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 341592Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 351592Srgrimes * SUCH DAMAGE. 361592Srgrimes * 3727074Ssteve * from: @(#)defs.h 8.1 (Berkeley) 6/4/93 381592Srgrimes * 3927074Ssteve * From: Utah Hdr: defs.h 3.1 92/07/06 401592Srgrimes * Author: Jeff Forys, University of Utah CSS 4169226Skris * 4269226Skris * $FreeBSD$ 431592Srgrimes */ 441592Srgrimes 451592Srgrimes#include "rmp.h" 461592Srgrimes#include "rmp_var.h" 471592Srgrimes 481592Srgrimes/* 491592Srgrimes** Common #define's and external variables. All other files should 501592Srgrimes** include this. 511592Srgrimes*/ 521592Srgrimes 531592Srgrimes/* 541592Srgrimes * This may be defined in <sys/param.h>, if not, it's defined here. 551592Srgrimes */ 561592Srgrimes#ifndef MAXHOSTNAMELEN 5769226Skris#define MAXHOSTNAMELEN 256 581592Srgrimes#endif 591592Srgrimes 601592Srgrimes/* 611592Srgrimes * SIGUSR1 and SIGUSR2 are defined in <signal.h> for 4.3BSD systems. 621592Srgrimes */ 631592Srgrimes#ifndef SIGUSR1 641592Srgrimes#define SIGUSR1 SIGEMT 651592Srgrimes#endif 661592Srgrimes#ifndef SIGUSR2 671592Srgrimes#define SIGUSR2 SIGFPE 681592Srgrimes#endif 691592Srgrimes 701592Srgrimes/* 711592Srgrimes * These can be faster & more efficient than strcmp()/strncmp()... 721592Srgrimes */ 731592Srgrimes#define STREQN(s1,s2) ((*s1 == *s2) && (strcmp(s1,s2) == 0)) 741592Srgrimes#define STRNEQN(s1,s2,n) ((*s1 == *s2) && (strncmp(s1,s2,n) == 0)) 751592Srgrimes 761592Srgrimes/* 771592Srgrimes * Configuration file limitations. 781592Srgrimes */ 791592Srgrimes#define C_MAXFILE 10 /* max number of boot-able files */ 801592Srgrimes#define C_LINELEN 1024 /* max length of line */ 811592Srgrimes 821592Srgrimes/* 831592Srgrimes * Direction of packet (used as argument to DispPkt). 841592Srgrimes */ 851592Srgrimes#define DIR_RCVD 0 861592Srgrimes#define DIR_SENT 1 871592Srgrimes#define DIR_NONE 2 881592Srgrimes 891592Srgrimes/* 901592Srgrimes * These need not be functions, so... 911592Srgrimes */ 921592Srgrimes#define FreeStr(str) free(str) 931592Srgrimes#define FreeClient(cli) free(cli) 941592Srgrimes#define GenSessID() (++SessionID ? SessionID: ++SessionID) 951592Srgrimes 961592Srgrimes/* 971592Srgrimes * Converting an Ethernet address to a string is done in many routines. 981592Srgrimes * Using `rmp.hp_hdr.saddr' works because this field is *never* changed; 991592Srgrimes * it will *always* contain the source address of the packet. 1001592Srgrimes */ 1011592Srgrimes#define EnetStr(rptr) GetEtherAddr(&(rptr)->rmp.hp_hdr.saddr[0]) 1021592Srgrimes 1031592Srgrimes/* 1041592Srgrimes * Every machine we can boot will have one of these allocated for it 1051592Srgrimes * (unless there are no restrictions on who we can boot). 1061592Srgrimes */ 1071592Srgrimestypedef struct client_s { 10827074Ssteve u_int8_t addr[RMP_ADDRLEN]; /* addr of machine */ 1091592Srgrimes char *files[C_MAXFILE]; /* boot-able files */ 1101592Srgrimes struct client_s *next; /* ptr to next */ 1111592Srgrimes} CLIENT; 1121592Srgrimes 1131592Srgrimes/* 1141592Srgrimes * Every active connection has one of these allocated for it. 1151592Srgrimes */ 1161592Srgrimestypedef struct rmpconn_s { 1171592Srgrimes struct rmp_packet rmp; /* RMP packet */ 1181592Srgrimes int rmplen; /* length of packet */ 1191592Srgrimes struct timeval tstamp; /* last time active */ 1201592Srgrimes int bootfd; /* open boot file */ 1211592Srgrimes struct rmpconn_s *next; /* ptr to next */ 1221592Srgrimes} RMPCONN; 1231592Srgrimes 1241592Srgrimes/* 1251592Srgrimes * All these variables are defined in "conf.c". 1261592Srgrimes */ 1271592Srgrimesextern char MyHost[]; /* this hosts' name */ 12827074Ssteveextern pid_t MyPid; /* this processes' ID */ 1291592Srgrimesextern int DebugFlg; /* set true if debugging */ 1301592Srgrimesextern int BootAny; /* set true if we can boot anyone */ 1311592Srgrimes 1321592Srgrimesextern char *ConfigFile; /* configuration file */ 1331592Srgrimesextern char *DfltConfig; /* default configuration file */ 1341592Srgrimesextern char *DbgFile; /* debug output file */ 1351592Srgrimesextern char *PidFile; /* file containing pid of server */ 1361592Srgrimesextern char *BootDir; /* directory w/boot files */ 1371592Srgrimes 1381592Srgrimesextern FILE *DbgFp; /* debug file pointer */ 1391592Srgrimesextern char *IntfName; /* interface we are attached to */ 1401592Srgrimes 14127074Ssteveextern u_int16_t SessionID; /* generated session ID */ 1421592Srgrimes 1431592Srgrimesextern char *BootFiles[]; /* list of boot files */ 1441592Srgrimes 1451592Srgrimesextern CLIENT *Clients; /* list of addrs we'll accept */ 1461592Srgrimesextern RMPCONN *RmpConns; /* list of active connections */ 1471592Srgrimes 14827074Ssteveextern u_int8_t RmpMcastAddr[]; /* RMP multicast address */ 1491592Srgrimes 15090377Simpvoid AddConn(RMPCONN *); 15190377Simpint BootDone(RMPCONN *); 15290377Simpvoid BpfClose(void); 15390377Simpchar *BpfGetIntfName(char **); 15490377Simpint BpfOpen(void); 15590377Simpint BpfRead(RMPCONN *, int); 15690377Simpint BpfWrite(RMPCONN *); 15790377Simpvoid DebugOff(int); 15890377Simpvoid DebugOn(int); 15990377Simpvoid DispPkt(RMPCONN *, int); 16090377Simpvoid DoTimeout(void); 16190377Simpvoid DspFlnm(u_int, char *); 16290377Simpvoid Exit(int); 16390377SimpCLIENT *FindClient(RMPCONN *); 16490377SimpRMPCONN *FindConn(RMPCONN *); 16590377Simpvoid FreeClients(void); 16690377Simpvoid FreeConn(RMPCONN *); 16790377Simpvoid FreeConns(void); 16890377Simpint GetBootFiles(void); 16990377Simpchar *GetEtherAddr(u_int8_t *); 17090377SimpCLIENT *NewClient(u_int8_t *); 17190377SimpRMPCONN *NewConn(RMPCONN *); 17290377Simpchar *NewStr(char *); 17390377Simpu_int8_t *ParseAddr(char *); 17490377Simpint ParseConfig(void); 17590377Simpvoid ProcessPacket(RMPCONN *, CLIENT *); 17690377Simpvoid ReConfig(int); 17790377Simpvoid RemoveConn(RMPCONN *); 17890377Simpint SendBootRepl(struct rmp_packet *, RMPCONN *, char *[]); 17990377Simpint SendFileNo(struct rmp_packet *, RMPCONN *, char *[]); 18090377Simpint SendPacket(RMPCONN *); 18190377Simpint SendReadRepl(RMPCONN *); 18290377Simpint SendServerID(RMPCONN *); 183