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