10559b331SSteve Price /* $NetBSD: defs.h,v 1.5 1995/10/06 05:12:14 thorpej Exp $ */ 20559b331SSteve Price 30559b331SSteve Price /* 40559b331SSteve Price * Copyright (c) 1988, 1992 The University of Utah and the Center 50559b331SSteve Price * for Software Science (CSS). 60559b331SSteve Price * Copyright (c) 1992, 1993 70559b331SSteve Price * The Regents of the University of California. All rights reserved. 80559b331SSteve Price * 90559b331SSteve Price * This code is derived from software contributed to Berkeley by 100559b331SSteve Price * the Center for Software Science of the University of Utah Computer 110559b331SSteve Price * Science Department. CSS requests users of this software to return 120559b331SSteve Price * to css-dist@cs.utah.edu any improvements that they make and grant 130559b331SSteve Price * CSS redistribution rights. 140559b331SSteve Price * 150559b331SSteve Price * Redistribution and use in source and binary forms, with or without 160559b331SSteve Price * modification, are permitted provided that the following conditions 170559b331SSteve Price * are met: 180559b331SSteve Price * 1. Redistributions of source code must retain the above copyright 190559b331SSteve Price * notice, this list of conditions and the following disclaimer. 200559b331SSteve Price * 2. Redistributions in binary form must reproduce the above copyright 210559b331SSteve Price * notice, this list of conditions and the following disclaimer in the 220559b331SSteve Price * documentation and/or other materials provided with the distribution. 230559b331SSteve Price * 3. All advertising materials mentioning features or use of this software 240559b331SSteve Price * must display the following acknowledgement: 250559b331SSteve Price * This product includes software developed by the University of 260559b331SSteve Price * California, Berkeley and its contributors. 270559b331SSteve Price * 4. Neither the name of the University nor the names of its contributors 280559b331SSteve Price * may be used to endorse or promote products derived from this software 290559b331SSteve Price * without specific prior written permission. 300559b331SSteve Price * 310559b331SSteve Price * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 320559b331SSteve Price * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 330559b331SSteve Price * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 340559b331SSteve Price * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 350559b331SSteve Price * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 360559b331SSteve Price * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 370559b331SSteve Price * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 380559b331SSteve Price * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 390559b331SSteve Price * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 400559b331SSteve Price * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 410559b331SSteve Price * SUCH DAMAGE. 420559b331SSteve Price * 430559b331SSteve Price * from: @(#)defs.h 8.1 (Berkeley) 6/4/93 440559b331SSteve Price * 450559b331SSteve Price * From: Utah Hdr: defs.h 3.1 92/07/06 460559b331SSteve Price * Author: Jeff Forys, University of Utah CSS 470559b331SSteve Price */ 480559b331SSteve Price 490559b331SSteve Price #include "rmp.h" 500559b331SSteve Price #include "rmp_var.h" 510559b331SSteve Price 520559b331SSteve Price /* 530559b331SSteve Price ** Common #define's and external variables. All other files should 540559b331SSteve Price ** include this. 550559b331SSteve Price */ 560559b331SSteve Price 570559b331SSteve Price /* 580559b331SSteve Price * This may be defined in <sys/param.h>, if not, it's defined here. 590559b331SSteve Price */ 600559b331SSteve Price #ifndef MAXHOSTNAMELEN 610559b331SSteve Price #define MAXHOSTNAMELEN 64 620559b331SSteve Price #endif 630559b331SSteve Price 640559b331SSteve Price /* 650559b331SSteve Price * SIGUSR1 and SIGUSR2 are defined in <signal.h> for 4.3BSD systems. 660559b331SSteve Price */ 670559b331SSteve Price #ifndef SIGUSR1 680559b331SSteve Price #define SIGUSR1 SIGEMT 690559b331SSteve Price #endif 700559b331SSteve Price #ifndef SIGUSR2 710559b331SSteve Price #define SIGUSR2 SIGFPE 720559b331SSteve Price #endif 730559b331SSteve Price 740559b331SSteve Price /* 750559b331SSteve Price * These can be faster & more efficient than strcmp()/strncmp()... 760559b331SSteve Price */ 770559b331SSteve Price #define STREQN(s1,s2) ((*s1 == *s2) && (strcmp(s1,s2) == 0)) 780559b331SSteve Price #define STRNEQN(s1,s2,n) ((*s1 == *s2) && (strncmp(s1,s2,n) == 0)) 790559b331SSteve Price 800559b331SSteve Price /* 810559b331SSteve Price * Configuration file limitations. 820559b331SSteve Price */ 830559b331SSteve Price #define C_MAXFILE 10 /* max number of boot-able files */ 840559b331SSteve Price #define C_LINELEN 1024 /* max length of line */ 850559b331SSteve Price 860559b331SSteve Price /* 870559b331SSteve Price * Direction of packet (used as argument to DispPkt). 880559b331SSteve Price */ 890559b331SSteve Price #define DIR_RCVD 0 900559b331SSteve Price #define DIR_SENT 1 910559b331SSteve Price #define DIR_NONE 2 920559b331SSteve Price 930559b331SSteve Price /* 940559b331SSteve Price * These need not be functions, so... 950559b331SSteve Price */ 960559b331SSteve Price #define FreeStr(str) free(str) 970559b331SSteve Price #define FreeClient(cli) free(cli) 980559b331SSteve Price #define GenSessID() (++SessionID ? SessionID: ++SessionID) 990559b331SSteve Price 1000559b331SSteve Price /* 1010559b331SSteve Price * Converting an Ethernet address to a string is done in many routines. 1020559b331SSteve Price * Using `rmp.hp_hdr.saddr' works because this field is *never* changed; 1030559b331SSteve Price * it will *always* contain the source address of the packet. 1040559b331SSteve Price */ 1050559b331SSteve Price #define EnetStr(rptr) GetEtherAddr(&(rptr)->rmp.hp_hdr.saddr[0]) 1060559b331SSteve Price 1070559b331SSteve Price /* 1080559b331SSteve Price * Every machine we can boot will have one of these allocated for it 1090559b331SSteve Price * (unless there are no restrictions on who we can boot). 1100559b331SSteve Price */ 1110559b331SSteve Price typedef struct client_s { 1120559b331SSteve Price u_int8_t addr[RMP_ADDRLEN]; /* addr of machine */ 1130559b331SSteve Price char *files[C_MAXFILE]; /* boot-able files */ 1140559b331SSteve Price struct client_s *next; /* ptr to next */ 1150559b331SSteve Price } CLIENT; 1160559b331SSteve Price 1170559b331SSteve Price /* 1180559b331SSteve Price * Every active connection has one of these allocated for it. 1190559b331SSteve Price */ 1200559b331SSteve Price typedef struct rmpconn_s { 1210559b331SSteve Price struct rmp_packet rmp; /* RMP packet */ 1220559b331SSteve Price int rmplen; /* length of packet */ 1230559b331SSteve Price struct timeval tstamp; /* last time active */ 1240559b331SSteve Price int bootfd; /* open boot file */ 1250559b331SSteve Price struct rmpconn_s *next; /* ptr to next */ 1260559b331SSteve Price } RMPCONN; 1270559b331SSteve Price 1280559b331SSteve Price /* 1290559b331SSteve Price * All these variables are defined in "conf.c". 1300559b331SSteve Price */ 1310559b331SSteve Price extern char MyHost[]; /* this hosts' name */ 1320559b331SSteve Price extern pid_t MyPid; /* this processes' ID */ 1330559b331SSteve Price extern int DebugFlg; /* set true if debugging */ 1340559b331SSteve Price extern int BootAny; /* set true if we can boot anyone */ 1350559b331SSteve Price 1360559b331SSteve Price extern char *ConfigFile; /* configuration file */ 1370559b331SSteve Price extern char *DfltConfig; /* default configuration file */ 1380559b331SSteve Price extern char *DbgFile; /* debug output file */ 1390559b331SSteve Price extern char *PidFile; /* file containing pid of server */ 1400559b331SSteve Price extern char *BootDir; /* directory w/boot files */ 1410559b331SSteve Price 1420559b331SSteve Price extern FILE *DbgFp; /* debug file pointer */ 1430559b331SSteve Price extern char *IntfName; /* interface we are attached to */ 1440559b331SSteve Price 1450559b331SSteve Price extern u_int16_t SessionID; /* generated session ID */ 1460559b331SSteve Price 1470559b331SSteve Price extern char *BootFiles[]; /* list of boot files */ 1480559b331SSteve Price 1490559b331SSteve Price extern CLIENT *Clients; /* list of addrs we'll accept */ 1500559b331SSteve Price extern RMPCONN *RmpConns; /* list of active connections */ 1510559b331SSteve Price 1520559b331SSteve Price extern u_int8_t RmpMcastAddr[]; /* RMP multicast address */ 1530559b331SSteve Price 1540559b331SSteve Price void AddConn __P((RMPCONN *)); 1550559b331SSteve Price int BootDone __P((RMPCONN *)); 1560559b331SSteve Price void BpfClose __P((void)); 1570559b331SSteve Price char *BpfGetIntfName __P((char **)); 1580559b331SSteve Price int BpfOpen __P((void)); 1590559b331SSteve Price int BpfRead __P((RMPCONN *, int)); 1600559b331SSteve Price int BpfWrite __P((RMPCONN *)); 1610559b331SSteve Price void DebugOff __P((int)); 1620559b331SSteve Price void DebugOn __P((int)); 1630559b331SSteve Price void DispPkt __P((RMPCONN *, int)); 1640559b331SSteve Price void DoTimeout __P((void)); 1650559b331SSteve Price void DspFlnm __P((u_int, char *)); 1660559b331SSteve Price void Exit __P((int)); 1670559b331SSteve Price CLIENT *FindClient __P((RMPCONN *)); 1680559b331SSteve Price RMPCONN *FindConn __P((RMPCONN *)); 1690559b331SSteve Price void FreeClients __P((void)); 1700559b331SSteve Price void FreeConn __P((RMPCONN *)); 1710559b331SSteve Price void FreeConns __P((void)); 1720559b331SSteve Price int GetBootFiles __P((void)); 1730559b331SSteve Price char *GetEtherAddr __P((u_int8_t *)); 1740559b331SSteve Price CLIENT *NewClient __P((u_int8_t *)); 1750559b331SSteve Price RMPCONN *NewConn __P((RMPCONN *)); 1760559b331SSteve Price char *NewStr __P((char *)); 1770559b331SSteve Price u_int8_t *ParseAddr __P((char *)); 1780559b331SSteve Price int ParseConfig __P((void)); 1790559b331SSteve Price void ProcessPacket __P((RMPCONN *, CLIENT *)); 1800559b331SSteve Price void ReConfig __P((int)); 1810559b331SSteve Price void RemoveConn __P((RMPCONN *)); 1820559b331SSteve Price int SendBootRepl __P((struct rmp_packet *, RMPCONN *, char *[])); 1830559b331SSteve Price int SendFileNo __P((struct rmp_packet *, RMPCONN *, char *[])); 1840559b331SSteve Price int SendPacket __P((RMPCONN *)); 1850559b331SSteve Price int SendReadRepl __P((RMPCONN *)); 1860559b331SSteve Price int SendServerID __P((RMPCONN *)); 187