]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/statd/notlist.h
0c6709ca7dd4dccaf8cc484e9906bd53c7cb03ea
[nfs-utils.git] / utils / statd / notlist.h
1 /* 
2  * Copyright (C) 1995, 1997-1999 Jeffrey A. Uphoff
3  * Major rewrite by Olaf Kirch, Dec. 1996.
4  *
5  * NSM for Linux.
6  */
7
8 #include <netinet/in.h>
9
10 /*
11  * Primary information structure.
12  */
13 struct notify_list {
14   mon                   mon;    /* Big honkin' NSM structure. */
15   struct in_addr        addr;   /* IP address for callback. */
16   unsigned short        port;   /* port number for callback */
17   short int             times;  /* Counter used for various things. */
18   int                   state;  /* For storing notified state for callbacks. */
19   struct notify_list    *next;  /* Linked list forward pointer. */
20   struct notify_list    *prev;  /* Linked list backward pointer. */
21   u_int32_t             xid;    /* XID of MS_NOTIFY RPC call */
22   time_t                when;   /* notify: timeout for re-xmit */
23   int                   type;   /* type of notify (REBOOT/CALLBACK) */
24 };
25
26 typedef struct notify_list notify_list;
27
28 #define NOTIFY_REBOOT   0       /* notify remote of our reboot */
29 #define NOTIFY_CALLBACK 1       /* notify client of remote reboot */
30
31 /*
32  * Global Variables
33  */
34 extern notify_list *    rtnl;   /* Run-time notify list */
35 extern notify_list *    notify; /* Pending RPC calls */
36
37 /*
38  * List-handling functions
39  */
40 extern notify_list *    nlist_new(char *, char *, int);
41 extern void             nlist_insert(notify_list **, notify_list *);
42 extern void             nlist_remove(notify_list **, notify_list *);
43 extern void             nlist_insert_timer(notify_list **, notify_list *);
44 extern notify_list *    nlist_clone(notify_list *);
45 extern void             nlist_free(notify_list **, notify_list *);
46 extern void             nlist_kill(notify_list **);
47 extern notify_list *    nlist_gethost(notify_list *, char *, int);
48
49 /* 
50  * List-handling macros.
51  * THESE INHERIT INFORMATION FROM PREVIOUSLY-DEFINED MACROS.
52  * (So don't change their order unless you study them first!)
53  */
54 #define NL_NEXT(L)      ((L)->next)
55 #define NL_FIRST        NL_NEXT
56 #define NL_PREV(L)      ((L)->prev)
57 #define NL_DATA(L)      ((L)->mon)
58 #define NL_ADDR(L)      ((L)->addr)
59 #define NL_STATE(L)     ((L)->state)
60 #define NL_TIMES(L)     ((L)->times)
61 #define NL_MON_ID(L)    (NL_DATA((L)).mon_id)
62 #define NL_PRIV(L)      (NL_DATA((L)).priv)
63 #define NL_MON_NAME(L)  (NL_MON_ID((L)).mon_name)
64 #define NL_MY_ID(L)     (NL_MON_ID((L)).my_id)
65 #define NL_MY_NAME(L)   (NL_MY_ID((L)).my_name)
66 #define NL_MY_PROC(L)   (NL_MY_ID((L)).my_proc)
67 #define NL_MY_PROG(L)   (NL_MY_ID((L)).my_prog)
68 #define NL_MY_VERS(L)   (NL_MY_ID((L)).my_vers)
69 #define NL_WHEN(L)      ((L)->when)
70 #define NL_TYPE(L)      ((L)->type)
71
72 #if 0
73 #define NL_ADD_NO_ZERO(LIST, ITEM)\
74   NL_PREV(NL_FIRST((LIST))) = (ITEM);\
75   NL_NEXT((ITEM)) = NL_FIRST((LIST));\
76   NL_FIRST((LIST)) = (ITEM);\
77   NL_PREV((ITEM)) = (LIST);\
78   NL_TIMES((ITEM)) = 0;
79
80 #define NL_ADD(LIST, ITEM)\
81   NL_ADD_NO_ZERO((LIST), (ITEM));\
82   NL_ADDR((ITEM)) = 0;\
83   NL_STATE((ITEM)) = 0;
84
85 #define NL_DEL(ITEM)\
86   NL_NEXT(NL_PREV((ITEM))) = NL_NEXT((ITEM));\
87   NL_PREV(NL_NEXT((ITEM))) = NL_PREV((ITEM));
88
89 #define NL_FREE(ITEM)\
90   if (NL_MY_NAME ((ITEM)))\
91     free (NL_MY_NAME ((ITEM)));\
92   if (NL_MON_NAME ((ITEM)))\
93     free (NL_MON_NAME((ITEM)));\
94   free ((ITEM));
95
96 #define NL_DEL_FREE(ITEM)\
97   NL_DEL((ITEM))\
98   NL_FREE((ITEM))
99
100 /* Yuck.  Kludge. */
101 #define NL_COPY(SRC, DEST)\
102   NL_TIMES((DEST)) = NL_TIMES((SRC));\
103   NL_STATE((DEST)) = NL_TIMES((SRC));\
104   NL_MY_PROC((DEST)) = NL_MY_PROC((SRC));\
105   NL_MY_PROG((DEST)) = NL_MY_PROG((SRC));\
106   NL_MY_VERS((DEST)) = NL_MY_VERS((SRC));\
107   NL_MON_NAME((DEST)) = xstrdup (NL_MON_NAME((SRC)));\
108   NL_MY_NAME((DEST)) = xstrdup (NL_MY_NAME((SRC)));\
109   memcpy (&NL_ADDR((DEST)), &NL_ADDR((SRC)), sizeof (u_long));\
110   memcpy (NL_PRIV((DEST)), NL_PRIV((SRC)), SM_PRIV_SIZE);
111 #endif