1/*-
2 * SPDX-License-Identifier: BSD-4-Clause
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
37#include "sm_inter.h"
38
39/* ------------------------------------------------------------------------- */
40/*
41  Data structures for recording monitored hosts
42
43  The information held by the status monitor comprises a list of hosts
44  that we have been asked to monitor, and, associated with each monitored
45  host, one or more clients to be called back if the monitored host crashes.
46
47  The list of monitored hosts must be retained over a crash, so that upon
48  re-boot we can call the SM_NOTIFY procedure in all those hosts so as to
49  cause them to start recovery processing.  On the other hand, the client
50  call-backs are not required to be preserved: they are assumed (in the
51  protocol design) to be local processes which will have crashed when
52  we did, and so are discarded on restart.
53
54  We handle this by keeping the list of monitored hosts in a file
55  (/var/statd.state) which is mmap()ed and whose format is described
56  by the typedef FileLayout.  The lists of client callbacks are chained
57  off this structure, but are held in normal memory and so will be
58  lost after a re-boot.  Hence the actual values of MonList * pointers
59  in the copy on disc have no significance, but their NULL/non-NULL
60  status indicates whether this host is actually being monitored or if it
61  is an empty slot in the file.
62*/
63
64typedef struct MonList_s
65{
66  struct MonList_s *next;	/* Next in list or NULL			*/
67  char notifyHost[SM_MAXSTRLEN + 1];	/* Host to notify		*/
68  int notifyProg;		/* RPC program number to call		*/
69  int notifyVers;		/* version number			*/
70  int notifyProc;		/* procedure number			*/
71  unsigned char notifyData[16];	/* Opaque data from caller		*/
72} MonList;
73
74typedef struct
75{
76  char hostname[SM_MAXSTRLEN + 1];	/* Name of monitored host	*/
77  int notifyReqd;		/* TRUE if we've crashed and not yet	*/
78				/* informed the monitored host		*/
79  MonList *monList;		/* List of clients to inform if we	*/
80				/* hear that the monitored host has	*/
81				/* crashed, NULL if no longer monitored	*/
82} HostInfo;
83
84
85/* Overall file layout.  						*/
86
87typedef struct
88{
89  int ourState;		/* State number as defined in statd protocol	*/
90  int noOfHosts;	/* Number of elements in hosts[]		*/
91  char reserved[248];	/* Reserved for future use			*/
92  HostInfo hosts[1];	/* vector of monitored hosts			*/
93} FileLayout;
94
95#define	HEADER_LEN (sizeof(FileLayout) - sizeof(HostInfo))
96
97/* ------------------------------------------------------------------------- */
98
99/* Global variables		*/
100
101extern FileLayout *status_info;	/* The mmap()ed status file		*/
102
103extern int debug;		/* =1 to enable diagnostics to syslog	*/
104
105/* Function prototypes		*/
106
107extern HostInfo *find_host(char * /*hostname*/, int /*create*/);
108extern void init_file(const char * /*filename*/);
109extern void notify_hosts(void);
110extern void sync_file(void);
111extern int sm_check_hostname(struct svc_req *req, char *arg);
112