defs.h revision 69226
11592Srgrimes/* 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. 211592Srgrimes * 3. All advertising materials mentioning features or use of this software 221592Srgrimes * must display the following acknowledgement: 231592Srgrimes * This product includes software developed by the University of 241592Srgrimes * California, Berkeley and its contributors. 251592Srgrimes * 4. Neither the name of the University nor the names of its contributors 261592Srgrimes * may be used to endorse or promote products derived from this software 271592Srgrimes * without specific prior written permission. 281592Srgrimes * 291592Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 301592Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 311592Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 321592Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 331592Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 341592Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 351592Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 361592Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 371592Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 381592Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 391592Srgrimes * SUCH DAMAGE. 401592Srgrimes * 4127074Ssteve * from: @(#)defs.h 8.1 (Berkeley) 6/4/93 421592Srgrimes * 4327074Ssteve * From: Utah Hdr: defs.h 3.1 92/07/06 441592Srgrimes * Author: Jeff Forys, University of Utah CSS 4569226Skris * 4669226Skris * $FreeBSD: head/libexec/rbootd/defs.h 69226 2000-11-26 22:18:11Z kris $ 471592Srgrimes */ 481592Srgrimes 491592Srgrimes#include "rmp.h" 501592Srgrimes#include "rmp_var.h" 511592Srgrimes 521592Srgrimes/* 531592Srgrimes** Common #define's and external variables. All other files should 541592Srgrimes** include this. 551592Srgrimes*/ 561592Srgrimes 571592Srgrimes/* 581592Srgrimes * This may be defined in <sys/param.h>, if not, it's defined here. 591592Srgrimes */ 601592Srgrimes#ifndef MAXHOSTNAMELEN 6169226Skris#define MAXHOSTNAMELEN 256 621592Srgrimes#endif 631592Srgrimes 641592Srgrimes/* 651592Srgrimes * SIGUSR1 and SIGUSR2 are defined in <signal.h> for 4.3BSD systems. 661592Srgrimes */ 671592Srgrimes#ifndef SIGUSR1 681592Srgrimes#define SIGUSR1 SIGEMT 691592Srgrimes#endif 701592Srgrimes#ifndef SIGUSR2 711592Srgrimes#define SIGUSR2 SIGFPE 721592Srgrimes#endif 731592Srgrimes 741592Srgrimes/* 751592Srgrimes * These can be faster & more efficient than strcmp()/strncmp()... 761592Srgrimes */ 771592Srgrimes#define STREQN(s1,s2) ((*s1 == *s2) && (strcmp(s1,s2) == 0)) 781592Srgrimes#define STRNEQN(s1,s2,n) ((*s1 == *s2) && (strncmp(s1,s2,n) == 0)) 791592Srgrimes 801592Srgrimes/* 811592Srgrimes * Configuration file limitations. 821592Srgrimes */ 831592Srgrimes#define C_MAXFILE 10 /* max number of boot-able files */ 841592Srgrimes#define C_LINELEN 1024 /* max length of line */ 851592Srgrimes 861592Srgrimes/* 871592Srgrimes * Direction of packet (used as argument to DispPkt). 881592Srgrimes */ 891592Srgrimes#define DIR_RCVD 0 901592Srgrimes#define DIR_SENT 1 911592Srgrimes#define DIR_NONE 2 921592Srgrimes 931592Srgrimes/* 941592Srgrimes * These need not be functions, so... 951592Srgrimes */ 961592Srgrimes#define FreeStr(str) free(str) 971592Srgrimes#define FreeClient(cli) free(cli) 981592Srgrimes#define GenSessID() (++SessionID ? SessionID: ++SessionID) 991592Srgrimes 1001592Srgrimes/* 1011592Srgrimes * Converting an Ethernet address to a string is done in many routines. 1021592Srgrimes * Using `rmp.hp_hdr.saddr' works because this field is *never* changed; 1031592Srgrimes * it will *always* contain the source address of the packet. 1041592Srgrimes */ 1051592Srgrimes#define EnetStr(rptr) GetEtherAddr(&(rptr)->rmp.hp_hdr.saddr[0]) 1061592Srgrimes 1071592Srgrimes/* 1081592Srgrimes * Every machine we can boot will have one of these allocated for it 1091592Srgrimes * (unless there are no restrictions on who we can boot). 1101592Srgrimes */ 1111592Srgrimestypedef struct client_s { 11227074Ssteve u_int8_t addr[RMP_ADDRLEN]; /* addr of machine */ 1131592Srgrimes char *files[C_MAXFILE]; /* boot-able files */ 1141592Srgrimes struct client_s *next; /* ptr to next */ 1151592Srgrimes} CLIENT; 1161592Srgrimes 1171592Srgrimes/* 1181592Srgrimes * Every active connection has one of these allocated for it. 1191592Srgrimes */ 1201592Srgrimestypedef struct rmpconn_s { 1211592Srgrimes struct rmp_packet rmp; /* RMP packet */ 1221592Srgrimes int rmplen; /* length of packet */ 1231592Srgrimes struct timeval tstamp; /* last time active */ 1241592Srgrimes int bootfd; /* open boot file */ 1251592Srgrimes struct rmpconn_s *next; /* ptr to next */ 1261592Srgrimes} RMPCONN; 1271592Srgrimes 1281592Srgrimes/* 1291592Srgrimes * All these variables are defined in "conf.c". 1301592Srgrimes */ 1311592Srgrimesextern char MyHost[]; /* this hosts' name */ 13227074Ssteveextern pid_t MyPid; /* this processes' ID */ 1331592Srgrimesextern int DebugFlg; /* set true if debugging */ 1341592Srgrimesextern int BootAny; /* set true if we can boot anyone */ 1351592Srgrimes 1361592Srgrimesextern char *ConfigFile; /* configuration file */ 1371592Srgrimesextern char *DfltConfig; /* default configuration file */ 1381592Srgrimesextern char *DbgFile; /* debug output file */ 1391592Srgrimesextern char *PidFile; /* file containing pid of server */ 1401592Srgrimesextern char *BootDir; /* directory w/boot files */ 1411592Srgrimes 1421592Srgrimesextern FILE *DbgFp; /* debug file pointer */ 1431592Srgrimesextern char *IntfName; /* interface we are attached to */ 1441592Srgrimes 14527074Ssteveextern u_int16_t SessionID; /* generated session ID */ 1461592Srgrimes 1471592Srgrimesextern char *BootFiles[]; /* list of boot files */ 1481592Srgrimes 1491592Srgrimesextern CLIENT *Clients; /* list of addrs we'll accept */ 1501592Srgrimesextern RMPCONN *RmpConns; /* list of active connections */ 1511592Srgrimes 15227074Ssteveextern u_int8_t RmpMcastAddr[]; /* RMP multicast address */ 1531592Srgrimes 1541592Srgrimesvoid AddConn __P((RMPCONN *)); 1551592Srgrimesint BootDone __P((RMPCONN *)); 1561592Srgrimesvoid BpfClose __P((void)); 1571592Srgrimeschar *BpfGetIntfName __P((char **)); 1581592Srgrimesint BpfOpen __P((void)); 1591592Srgrimesint BpfRead __P((RMPCONN *, int)); 1601592Srgrimesint BpfWrite __P((RMPCONN *)); 1611592Srgrimesvoid DebugOff __P((int)); 1621592Srgrimesvoid DebugOn __P((int)); 1631592Srgrimesvoid DispPkt __P((RMPCONN *, int)); 1641592Srgrimesvoid DoTimeout __P((void)); 1651592Srgrimesvoid DspFlnm __P((u_int, char *)); 1661592Srgrimesvoid Exit __P((int)); 1671592SrgrimesCLIENT *FindClient __P((RMPCONN *)); 1681592SrgrimesRMPCONN *FindConn __P((RMPCONN *)); 1691592Srgrimesvoid FreeClients __P((void)); 1701592Srgrimesvoid FreeConn __P((RMPCONN *)); 1711592Srgrimesvoid FreeConns __P((void)); 1721592Srgrimesint GetBootFiles __P((void)); 17327074Sstevechar *GetEtherAddr __P((u_int8_t *)); 17427074SsteveCLIENT *NewClient __P((u_int8_t *)); 1751592SrgrimesRMPCONN *NewConn __P((RMPCONN *)); 1761592Srgrimeschar *NewStr __P((char *)); 17727074Ssteveu_int8_t *ParseAddr __P((char *)); 1781592Srgrimesint ParseConfig __P((void)); 1791592Srgrimesvoid ProcessPacket __P((RMPCONN *, CLIENT *)); 1801592Srgrimesvoid ReConfig __P((int)); 1811592Srgrimesvoid RemoveConn __P((RMPCONN *)); 1821592Srgrimesint SendBootRepl __P((struct rmp_packet *, RMPCONN *, char *[])); 1831592Srgrimesint SendFileNo __P((struct rmp_packet *, RMPCONN *, char *[])); 1841592Srgrimesint SendPacket __P((RMPCONN *)); 1851592Srgrimesint SendReadRepl __P((RMPCONN *)); 1861592Srgrimesint SendServerID __P((RMPCONN *)); 187