r12677: get rid of the special cases for the local wins owner table entry,
[kai/samba-autobuild/.git] / source4 / wrepl_server / wrepl_server.h
1 /* 
2    Unix SMB/CIFS implementation.
3    
4    WINS Replication server
5    
6    Copyright (C) Stefan Metzmacher      2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 struct wreplsrv_service;
24 struct wreplsrv_in_connection;
25 struct wreplsrv_out_connection;
26 struct wreplsrv_partner;
27
28 #define WREPLSRV_VALID_ASSOC_CTX        0x12345678
29 #define WREPLSRV_INVALID_ASSOC_CTX      0x0000000a
30
31 /*
32   state of an incoming wrepl call
33 */
34 struct wreplsrv_in_call {
35         struct wreplsrv_in_connection *wreplconn;
36         struct wrepl_packet req_packet;
37         struct wrepl_packet rep_packet;
38         BOOL terminate_after_send;
39 };
40
41 /*
42   state of an incoming wrepl connection
43 */
44 struct wreplsrv_in_connection {
45         struct wreplsrv_in_connection *prev,*next;
46         struct stream_connection *conn;
47         struct packet_context *packet;
48
49         /* our global service context */
50         struct wreplsrv_service *service;
51
52         /*
53          * the partner that connects us,
54          * can be NULL, when we got a connection
55          * from an unknown address
56          */
57         struct wreplsrv_partner *partner;
58
59         /*
60          * we need to take care of our own ip address,
61          * as this is the WINS-Owner ID the peer expect
62          * from us.
63          */
64         const char *our_ip;
65
66         /* keep track of the assoc_ctx's */
67         struct {
68                 BOOL stopped;
69                 uint32_t our_ctx;
70                 uint32_t peer_ctx;
71         } assoc_ctx;
72 };
73
74 /*
75   state of an outcoming wrepl connection
76 */
77 struct wreplsrv_out_connection {
78         /* our global service context */
79         struct wreplsrv_service *service;
80
81         /*
82          * the partner that connects us,
83          * can be NULL, when we got a connection
84          * from an unknown address
85          */
86         struct wreplsrv_partner *partner;
87
88         /* keep track of the assoc_ctx's */
89         struct {
90                 uint32_t our_ctx;
91                 uint32_t peer_ctx;
92         } assoc_ctx;
93
94         /* 
95          * the client socket to the partner,
96          * NULL if not yet connected
97          */
98         struct wrepl_socket *sock;
99 };
100
101 enum winsrepl_partner_type {
102         WINSREPL_PARTNER_NONE = 0x0,
103         WINSREPL_PARTNER_PULL = 0x1,
104         WINSREPL_PARTNER_PUSH = 0x2,
105         WINSREPL_PARTNER_BOTH = (WINSREPL_PARTNER_PULL | WINSREPL_PARTNER_PUSH)
106 };
107
108 #define WINSREPL_DEFAULT_PULL_INTERVAL (30*60)
109 #define WINSREPL_DEFAULT_PULL_RETRY_INTERVAL (30)
110
111 #define WINSREPL_DEFAULT_PUSH_CHANGE_COUNT (0)
112
113 /*
114  this represents one of our configured partners
115 */
116 struct wreplsrv_partner {
117         struct wreplsrv_partner *prev,*next;
118
119         /* our global service context */
120         struct wreplsrv_service *service;
121
122         /* the netbios name of the partner, mostly just for debugging */
123         const char *name;
124
125         /* the ip-address of the partner */
126         const char *address;
127
128         /* 
129          * as wins partners identified by ip-address, we need to use a specific source-ip
130          *  when we want to connect to the partner
131          */
132         const char *our_address;
133
134         /* the type of the partner, pull, push or both */
135         enum winsrepl_partner_type type;
136
137         /* pull specific options */
138         struct {
139                 /* the interval between 2 pull replications to the partner */
140                 uint32_t interval;
141
142                 /* the retry_interval if a pull cycle failed to the partner */
143                 uint32_t retry_interval;
144
145                 /* the error count till the last success */
146                 uint32_t error_count;
147
148                 /* the status of the last pull cycle */
149                 NTSTATUS last_status;
150
151                 /* the timestamp of the next pull try */
152                 struct timeval next_run;
153
154                 /* this is a list of each wins_owner the partner knows about */
155                 struct wreplsrv_owner *table;
156
157                 /* the outgoing connection to the partner */
158                 struct wreplsrv_out_connection *wreplconn;
159
160                 /* the current pending pull cycle request */
161                 struct composite_context *creq;
162
163                 /* the pull cycle io params */
164                 struct wreplsrv_pull_cycle_io *cycle_io;
165
166                 /* the current timed_event to the next pull cycle */
167                 struct timed_event *te;
168         } pull;
169
170         /* push specific options */
171         struct {
172                 /* change count till push notification */
173                 uint32_t change_count;
174
175                 /* the last wins db seqnumber we know about */
176                 uint64_t seqnumber;
177
178                 /* we should use WREPL_REPL_INFORM* messages to this partner */
179                 BOOL use_inform;
180
181                 /* the error count till the last success */
182                 uint32_t error_count;
183
184                 /* the status of the last push cycle */
185                 NTSTATUS last_status;
186
187                 /* the outgoing connection to the partner */
188                 struct wreplsrv_out_connection *wreplconn;
189
190                 /* the current push notification */
191                 struct composite_context *creq;
192
193                 /* the pull cycle io params */
194                 struct wreplsrv_push_notify_io *notify_io;
195         } push;
196 };
197
198 struct wreplsrv_owner {
199         struct wreplsrv_owner *prev,*next;
200
201         /* this hold the owner_id (address), min_version, max_version and partner_type */
202         struct wrepl_wins_owner owner;
203
204         /* can be NULL if this owner isn't a configure partner */
205         struct wreplsrv_partner *partner; 
206 };
207
208 /*
209   state of the whole wrepl service
210 */
211 struct wreplsrv_service {
212         /* the whole wrepl service is in one task */
213         struct task_server *task;
214
215         /* the time the service was started */
216         struct timeval startup_time;
217
218         /* the winsdb handle */
219         struct winsdb_handle *wins_db;
220
221         /* some configuration */
222         struct {
223                 /* the wins config db handle */
224                 struct ldb_context *ldb;
225
226                 /* 
227                  * the interval (in secs) till an active record will be marked as RELEASED 
228                  */
229                 uint32_t renew_interval;
230
231                 /* 
232                  * the interval (in secs) a record remains in RELEASED state,
233                  * before it will be marked as TOMBSTONE
234                  * (also known as extinction interval)
235                  */
236                 uint32_t tombstone_interval;
237
238                 /* 
239                  * the interval (in secs) a record remains in TOMBSTONE state,
240                  * before it will be removed from the database.
241                  * See also 'tombstone_extra_timeout'.
242                  * (also known as extinction timeout)
243                  */
244                 uint32_t tombstone_timeout;
245
246                 /* 
247                  * the interval (in secs) a record remains in TOMBSTONE state,
248                  * even after 'tombstone_timeout' passes the current timestamp.
249                  * this is the minimum uptime of the wrepl service, before
250                  * we start delete tombstones. This is to prevent deletion of
251                  * tombstones, without replacte them.
252                  */
253                 uint32_t tombstone_extra_timeout;
254
255                 /* 
256                  * the interval (in secs) till a replica record will be verified
257                  * with the owning wins server
258                  */
259                 uint32_t verify_interval;
260
261                 /* 
262                  * the interval (in secs) till a do a database cleanup
263                  */
264                 uint32_t scavenging_interval;
265
266                 /* 
267                  * the interval (in secs) to the next periodic processing
268                  * (this is the maximun interval)
269                  */
270                 uint32_t periodic_interval;
271         } config;
272
273         /* all incoming connections */
274         struct wreplsrv_in_connection *in_connections;
275
276         /* all partners (pull and push) */
277         struct wreplsrv_partner *partners;
278
279         /*
280          * this is our local wins_owner entry, this is also in the table list
281          * but we need a pointer to it, because we need to update it on each 
282          * query to wreplsrv_find_owner(), as the local records can be added
283          * to the wins.ldb from external tools and the winsserver
284          */
285         struct wreplsrv_owner *owner;
286
287         /* this is a list of each wins_owner we know about in our database */
288         struct wreplsrv_owner *table;
289
290         /* some stuff for periodic processing */
291         struct {
292                 /*
293                  * the timestamp for the next event,
294                  * this is the timstamp passed to event_add_timed()
295                  */
296                 struct timeval next_event;
297
298                 /* here we have a reference to the timed event the schedules the periodic stuff */
299                 struct timed_event *te;
300         } periodic;
301
302         /* some stuff for scavenging processing */
303         struct {
304                 /*
305                  * the timestamp for the next scavenging run,
306                  * this is the timstamp passed to event_add_timed()
307                  */
308                 struct timeval next_run;
309
310                 /*
311                  * are we currently inside a scavenging run
312                  */
313                 BOOL processing;        
314         } scavenging;
315 };
316
317 #include "wrepl_server/wrepl_server_proto.h"