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