statd.h revision 99783
114125Speter/* 214125Speter * Copyright (c) 1995 314125Speter * A.R. Gordon (andrew.gordon@net-tel.co.uk). All rights reserved. 414125Speter * 514125Speter * Redistribution and use in source and binary forms, with or without 614125Speter * modification, are permitted provided that the following conditions 714125Speter * are met: 814125Speter * 1. Redistributions of source code must retain the above copyright 914125Speter * notice, this list of conditions and the following disclaimer. 1014125Speter * 2. Redistributions in binary form must reproduce the above copyright 1114125Speter * notice, this list of conditions and the following disclaimer in the 1214125Speter * documentation and/or other materials provided with the distribution. 1314125Speter * 3. All advertising materials mentioning features or use of this software 1414125Speter * must display the following acknowledgement: 1514125Speter * This product includes software developed for the FreeBSD project 1614125Speter * 4. Neither the name of the author nor the names of any co-contributors 1714125Speter * may be used to endorse or promote products derived from this software 1814125Speter * without specific prior written permission. 1914125Speter * 2014125Speter * THIS SOFTWARE IS PROVIDED BY ANDREW GORDON AND CONTRIBUTORS ``AS IS'' AND 2114125Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2214125Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2314125Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2414125Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2514125Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2614125Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2714125Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2814125Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2914125Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3014125Speter * SUCH DAMAGE. 3114125Speter * 3274462Salfred * $FreeBSD: head/usr.sbin/rpc.statd/statd.h 99783 2002-07-11 17:11:42Z alfred $ 3314125Speter */ 3414125Speter 3514125Speter 3614125Speter 3714982Speter#include "sm_inter.h" 3814125Speter 3914125Speter/* ------------------------------------------------------------------------- */ 4014125Speter/* 4114125Speter Data structures for recording monitored hosts 4214125Speter 4314125Speter The information held by the status monitor comprises a list of hosts 4414125Speter that we have been asked to monitor, and, associated with each monitored 4514125Speter host, one or more clients to be called back if the monitored host crashes. 4614125Speter 4714125Speter The list of monitored hosts must be retained over a crash, so that upon 4814125Speter re-boot we can call the SM_NOTIFY procedure in all those hosts so as to 4914125Speter cause them to start recovery processing. On the other hand, the client 5014125Speter call-backs are not required to be preserved: they are assumed (in the 5114125Speter protocol design) to be local processes which will have crashed when 5214125Speter we did, and so are discarded on restart. 5314125Speter 5414125Speter We handle this by keeping the list of monitored hosts in a file 5514125Speter (/var/statd.state) which is mmap()ed and whose format is described 5614125Speter by the typedef FileLayout. The lists of client callbacks are chained 5714125Speter off this structure, but are held in normal memory and so will be 5814125Speter lost after a re-boot. Hence the actual values of MonList * pointers 5914125Speter in the copy on disc have no significance, but their NULL/non-NULL 6014125Speter status indicates whether this host is actually being monitored or if it 6114125Speter is an empty slot in the file. 6214125Speter*/ 6314125Speter 6414125Spetertypedef struct MonList_s 6514125Speter{ 6614125Speter struct MonList_s *next; /* Next in list or NULL */ 6714125Speter char notifyHost[SM_MAXSTRLEN + 1]; /* Host to notify */ 6814125Speter int notifyProg; /* RPC program number to call */ 6914125Speter int notifyVers; /* version number */ 7014125Speter int notifyProc; /* procedure number */ 7114125Speter unsigned char notifyData[16]; /* Opaque data from caller */ 7214125Speter} MonList; 7314125Speter 7414125Spetertypedef struct 7514125Speter{ 7614125Speter char hostname[SM_MAXSTRLEN + 1]; /* Name of monitored host */ 7714125Speter int notifyReqd; /* TRUE if we've crashed and not yet */ 7814125Speter /* informed the monitored host */ 7914125Speter MonList *monList; /* List of clients to inform if we */ 8014125Speter /* hear that the monitored host has */ 8114125Speter /* crashed, NULL if no longer monitored */ 8214125Speter} HostInfo; 8314125Speter 8414125Speter 8514125Speter/* Overall file layout. */ 8614125Speter 8714125Spetertypedef struct 8814125Speter{ 8914125Speter int ourState; /* State number as defined in statd protocol */ 9014125Speter int noOfHosts; /* Number of elements in hosts[] */ 9114125Speter char reserved[248]; /* Reserved for future use */ 9214125Speter HostInfo hosts[1]; /* vector of monitored hosts */ 9314125Speter} FileLayout; 9414125Speter 9514125Speter#define HEADER_LEN (sizeof(FileLayout) - sizeof(HostInfo)) 9614125Speter 9714125Speter/* ------------------------------------------------------------------------- */ 9814125Speter 9914125Speter/* Global variables */ 10014125Speter 10114125Speterextern FileLayout *status_info; /* The mmap()ed status file */ 10214125Speter 10314125Speterextern int debug; /* =1 to enable diagnostics to syslog */ 10414125Speter 10514125Speter/* Function prototypes */ 10614125Speter 10714125Speterextern HostInfo *find_host(char * /*hostname*/, int /*create*/); 10814125Speterextern void init_file(char * /*filename*/); 10914125Speterextern void notify_hosts(void); 11014125Speterextern void sync_file(void); 11199783Salfredextern int sm_check_hostname(struct svc_req *req, char *arg); 112