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