Remove advertising header from lib/ and libexec/
[dragonfly.git] / libexec / rbootd / defs.h
1 /*
2  * Copyright (c) 1988, 1992 The University of Utah and the Center
3  *      for Software Science (CSS).
4  * Copyright (c) 1992, 1993
5  *      The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * the Center for Software Science of the University of Utah Computer
9  * Science Department.  CSS requests users of this software to return
10  * to css-dist@cs.utah.edu any improvements that they make and grant
11  * CSS redistribution rights.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *      from: @(#)defs.h        8.1 (Berkeley) 6/4/93
38  *
39  * From: Utah Hdr: defs.h 3.1 92/07/06
40  * Author: Jeff Forys, University of Utah CSS
41  *
42  * $FreeBSD: src/libexec/rbootd/defs.h,v 1.2.6.1 2001/02/18 02:54:11 kris Exp $
43  * $DragonFly: src/libexec/rbootd/defs.h,v 1.3 2003/11/14 03:54:30 dillon Exp $
44  */
45
46 #include "rmp.h"
47 #include "rmp_var.h"
48
49 /*
50 **  Common #define's and external variables.  All other files should
51 **  include this.
52 */
53
54 /*
55  *  This may be defined in <sys/param.h>, if not, it's defined here.
56  */
57 #ifndef MAXHOSTNAMELEN
58 #define MAXHOSTNAMELEN 256
59 #endif
60
61 /*
62  *  SIGUSR1 and SIGUSR2 are defined in <signal.h> for 4.3BSD systems.
63  */
64 #ifndef SIGUSR1
65 #define SIGUSR1 SIGEMT
66 #endif
67 #ifndef SIGUSR2
68 #define SIGUSR2 SIGFPE
69 #endif
70
71 /*
72  *  These can be faster & more efficient than strcmp()/strncmp()...
73  */
74 #define STREQN(s1,s2)           ((*s1 == *s2) && (strcmp(s1,s2) == 0))
75 #define STRNEQN(s1,s2,n)        ((*s1 == *s2) && (strncmp(s1,s2,n) == 0))
76
77 /*
78  *  Configuration file limitations.
79  */
80 #define C_MAXFILE       10              /* max number of boot-able files */
81 #define C_LINELEN       1024            /* max length of line */
82
83 /*
84  *  Direction of packet (used as argument to DispPkt).
85  */
86 #define DIR_RCVD        0
87 #define DIR_SENT        1
88 #define DIR_NONE        2
89
90 /*
91  *  These need not be functions, so...
92  */
93 #define FreeStr(str)    free(str)
94 #define FreeClient(cli) free(cli)
95 #define GenSessID()     (++SessionID ? SessionID: ++SessionID)
96
97 /*
98  *  Converting an Ethernet address to a string is done in many routines.
99  *  Using `rmp.hp_hdr.saddr' works because this field is *never* changed;
100  *  it will *always* contain the source address of the packet.
101  */
102 #define EnetStr(rptr)   GetEtherAddr(&(rptr)->rmp.hp_hdr.saddr[0])
103
104 /*
105  *  Every machine we can boot will have one of these allocated for it
106  *  (unless there are no restrictions on who we can boot).
107  */
108 typedef struct client_s {
109         u_int8_t                addr[RMP_ADDRLEN];      /* addr of machine */
110         char                    *files[C_MAXFILE];      /* boot-able files */
111         struct client_s         *next;                  /* ptr to next */
112 } CLIENT;
113
114 /*
115  *  Every active connection has one of these allocated for it.
116  */
117 typedef struct rmpconn_s {
118         struct rmp_packet       rmp;                    /* RMP packet */
119         int                     rmplen;                 /* length of packet */
120         struct timeval          tstamp;                 /* last time active */
121         int                     bootfd;                 /* open boot file */
122         struct rmpconn_s        *next;                  /* ptr to next */
123 } RMPCONN;
124
125 /*
126  *  All these variables are defined in "conf.c".
127  */
128 extern  char    MyHost[];               /* this hosts' name */
129 extern  pid_t   MyPid;                  /* this processes' ID */
130 extern  int     DebugFlg;               /* set true if debugging */
131 extern  int     BootAny;                /* set true if we can boot anyone */
132
133 extern  char    *ConfigFile;            /* configuration file */
134 extern  char    *DfltConfig;            /* default configuration file */
135 extern  char    *DbgFile;               /* debug output file */
136 extern  char    *PidFile;               /* file containing pid of server */
137 extern  char    *BootDir;               /* directory w/boot files */
138
139 extern  FILE    *DbgFp;                 /* debug file pointer */
140 extern  char    *IntfName;              /* interface we are attached to */
141
142 extern  u_int16_t SessionID;            /* generated session ID */
143
144 extern  char    *BootFiles[];           /* list of boot files */
145
146 extern  CLIENT  *Clients;               /* list of addrs we'll accept */
147 extern  RMPCONN *RmpConns;              /* list of active connections */
148
149 extern  u_int8_t RmpMcastAddr[];        /* RMP multicast address */
150
151 void     AddConn (RMPCONN *);
152 int      BootDone (RMPCONN *);
153 void     BpfClose (void);
154 char    *BpfGetIntfName (char **);
155 int      BpfOpen (void);
156 int      BpfRead (RMPCONN *, int);
157 int      BpfWrite (RMPCONN *);
158 void     DebugOff (int);
159 void     DebugOn (int);
160 void     DispPkt (RMPCONN *, int);
161 void     DoTimeout (void);
162 void     DspFlnm (u_int, char *);
163 void     Exit (int);
164 CLIENT  *FindClient (RMPCONN *);
165 RMPCONN *FindConn (RMPCONN *);
166 void     FreeClients (void);
167 void     FreeConn (RMPCONN *);
168 void     FreeConns (void);
169 int      GetBootFiles (void);
170 char    *GetEtherAddr (u_int8_t *);
171 CLIENT  *NewClient (u_int8_t *);
172 RMPCONN *NewConn (RMPCONN *);
173 char    *NewStr (char *);
174 u_int8_t *ParseAddr (char *);
175 int      ParseConfig (void);
176 void     ProcessPacket (RMPCONN *, CLIENT *);
177 void     ReConfig (int);
178 void     RemoveConn (RMPCONN *);
179 int      SendBootRepl (struct rmp_packet *, RMPCONN *, char *[]);
180 int      SendFileNo (struct rmp_packet *, RMPCONN *, char *[]);
181 int      SendPacket (RMPCONN *);
182 int      SendReadRepl (RMPCONN *);
183 int      SendServerID (RMPCONN *);