xref: /freebsd/usr.sbin/rpc.statd/statd.h (revision 380a989b3223d455375b4fae70fd0b9bdd43bafb)
1 /*
2  * Copyright (c) 1995
3  *	A.R. Gordon (andrew.gordon@net-tel.co.uk).  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed for the FreeBSD project
16  * 4. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY ANDREW GORDON AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  */
33 
34 
35 
36 #include "sm_inter.h"
37 
38 /* These pieces are missing from the distributed sm_inter.x, which	*/
39 /* omits the SM_NOTIFY procedure used between cooperating rpc.statd's	*/
40 
41 #define SM_NOTIFY ((u_long)6)
42 extern void *sm_notify_1();
43 
44 struct stat_chge
45 {
46   char *mon_name;
47   int state;
48 };
49 typedef struct stat_chge stat_chge;
50 bool_t xdr_stat_chge();
51 
52 /* ------------------------------------------------------------------------- */
53 /*
54   Data structures for recording monitored hosts
55 
56   The information held by the status monitor comprises a list of hosts
57   that we have been asked to monitor, and, associated with each monitored
58   host, one or more clients to be called back if the monitored host crashes.
59 
60   The list of monitored hosts must be retained over a crash, so that upon
61   re-boot we can call the SM_NOTIFY procedure in all those hosts so as to
62   cause them to start recovery processing.  On the other hand, the client
63   call-backs are not required to be preserved: they are assumed (in the
64   protocol design) to be local processes which will have crashed when
65   we did, and so are discarded on restart.
66 
67   We handle this by keeping the list of monitored hosts in a file
68   (/var/statd.state) which is mmap()ed and whose format is described
69   by the typedef FileLayout.  The lists of client callbacks are chained
70   off this structure, but are held in normal memory and so will be
71   lost after a re-boot.  Hence the actual values of MonList * pointers
72   in the copy on disc have no significance, but their NULL/non-NULL
73   status indicates whether this host is actually being monitored or if it
74   is an empty slot in the file.
75 */
76 
77 typedef struct MonList_s
78 {
79   struct MonList_s *next;	/* Next in list or NULL			*/
80   char notifyHost[SM_MAXSTRLEN + 1];	/* Host to notify		*/
81   int notifyProg;		/* RPC program number to call		*/
82   int notifyVers;		/* version number			*/
83   int notifyProc;		/* procedure number			*/
84   unsigned char notifyData[16];	/* Opaque data from caller		*/
85 } MonList;
86 
87 typedef struct
88 {
89   char hostname[SM_MAXSTRLEN + 1];	/* Name of monitored host	*/
90   int notifyReqd;		/* TRUE if we've crashed and not yet	*/
91 				/* informed the monitored host		*/
92   MonList *monList;		/* List of clients to inform if we	*/
93 				/* hear that the monitored host has	*/
94 				/* crashed, NULL if no longer monitored	*/
95 } HostInfo;
96 
97 
98 /* Overall file layout.  						*/
99 
100 typedef struct
101 {
102   int ourState;		/* State number as defined in statd protocol	*/
103   int noOfHosts;	/* Number of elements in hosts[]		*/
104   char reserved[248];	/* Reserved for future use			*/
105   HostInfo hosts[1];	/* vector of monitored hosts			*/
106 } FileLayout;
107 
108 #define	HEADER_LEN (sizeof(FileLayout) - sizeof(HostInfo))
109 
110 /* ------------------------------------------------------------------------- */
111 
112 /* Global variables		*/
113 
114 extern FileLayout *status_info;	/* The mmap()ed status file		*/
115 
116 extern int debug;		/* =1 to enable diagnostics to syslog	*/
117 
118 /* Function prototypes		*/
119 
120 extern HostInfo *find_host(char * /*hostname*/, int /*create*/);
121 extern void init_file(char * /*filename*/);
122 extern void notify_hosts(void);
123 extern void sync_file(void);
124