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