s3: Fix bug #9085.
[Samba.git] / source4 / wrepl_server / wrepl_server.h
blobd92e524c353714a42e0af148c0116d1e9317a7fc
1 /*
2 Unix SMB/CIFS implementation.
4 WINS Replication server
6 Copyright (C) Stefan Metzmacher 2005
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.
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.
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/>.
22 struct wreplsrv_service;
23 struct wreplsrv_in_connection;
24 struct wreplsrv_out_connection;
25 struct wreplsrv_partner;
27 #define WREPLSRV_VALID_ASSOC_CTX 0x12345678
28 #define WREPLSRV_INVALID_ASSOC_CTX 0x0000000a
31 state of an incoming wrepl call
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;
41 state of an incoming wrepl connection
43 struct wreplsrv_in_connection {
44 struct wreplsrv_in_connection *prev,*next;
45 struct stream_connection *conn;
46 struct packet_context *packet;
48 /* our global service context */
49 struct wreplsrv_service *service;
52 * the partner that connects us,
53 * can be NULL, when we got a connection
54 * from an unknown address
56 struct wreplsrv_partner *partner;
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;
67 state of an outgoing wrepl connection
69 struct wreplsrv_out_connection {
70 /* our global service context */
71 struct wreplsrv_service *service;
74 * the partner we connect
76 struct wreplsrv_partner *partner;
78 /* keep track of the assoc_ctx's */
79 struct {
80 uint32_t our_ctx;
81 uint32_t peer_ctx;
82 uint16_t peer_major;
83 } assoc_ctx;
85 /*
86 * the client socket to the partner,
87 * NULL if not yet connected
89 struct wrepl_socket *sock;
92 enum winsrepl_partner_type {
93 WINSREPL_PARTNER_NONE = 0x0,
94 WINSREPL_PARTNER_PULL = 0x1,
95 WINSREPL_PARTNER_PUSH = 0x2,
96 WINSREPL_PARTNER_BOTH = (WINSREPL_PARTNER_PULL | WINSREPL_PARTNER_PUSH)
99 #define WINSREPL_DEFAULT_PULL_INTERVAL (30*60)
100 #define WINSREPL_DEFAULT_PULL_RETRY_INTERVAL (30)
102 #define WINSREPL_DEFAULT_PUSH_CHANGE_COUNT (0)
105 this represents one of our configured partners
107 struct wreplsrv_partner {
108 struct wreplsrv_partner *prev,*next;
110 /* our global service context */
111 struct wreplsrv_service *service;
113 /* the netbios name of the partner, mostly just for debugging */
114 const char *name;
116 /* the ip-address of the partner */
117 const char *address;
120 * as wins partners identified by ip-address, we need to use a specific source-ip
121 * when we want to connect to the partner
123 const char *our_address;
125 /* the type of the partner, pull, push or both */
126 enum winsrepl_partner_type type;
128 /* pull specific options */
129 struct {
130 /* the interval between 2 pull replications to the partner */
131 uint32_t interval;
133 /* the retry_interval if a pull cycle failed to the partner */
134 uint32_t retry_interval;
136 /* the error count till the last success */
137 uint32_t error_count;
139 /* the status of the last pull cycle */
140 NTSTATUS last_status;
142 /* the timestamp of the next pull try */
143 struct timeval next_run;
145 /* this is a list of each wins_owner the partner knows about */
146 struct wreplsrv_owner *table;
148 /* the outgoing connection to the partner */
149 struct wreplsrv_out_connection *wreplconn;
151 /* the current pending pull cycle request */
152 struct composite_context *creq;
154 /* the pull cycle io params */
155 struct wreplsrv_pull_cycle_io *cycle_io;
157 /* the current timed_event to the next pull cycle */
158 struct tevent_timer *te;
159 } pull;
161 /* push specific options */
162 struct {
163 /* change count till push notification */
164 uint32_t change_count;
166 /* the last wins db maxVersion have reported to the partner */
167 uint64_t maxVersionID;
169 /* we should use WREPL_REPL_INFORM* messages to this partner */
170 bool use_inform;
172 /* the error count till the last success */
173 uint32_t error_count;
175 /* the status of the last push cycle */
176 NTSTATUS last_status;
178 /* the outgoing connection to the partner */
179 struct wreplsrv_out_connection *wreplconn;
181 /* the current push notification */
182 struct composite_context *creq;
184 /* the pull cycle io params */
185 struct wreplsrv_push_notify_io *notify_io;
186 } push;
189 struct wreplsrv_owner {
190 struct wreplsrv_owner *prev,*next;
192 /* this hold the owner_id (address), min_version, max_version and partner_type */
193 struct wrepl_wins_owner owner;
195 /* can be NULL if this owner isn't a configure partner */
196 struct wreplsrv_partner *partner;
200 state of the whole wrepl service
202 struct wreplsrv_service {
203 /* the whole wrepl service is in one task */
204 struct task_server *task;
206 /* the time the service was started */
207 struct timeval startup_time;
209 /* the winsdb handle */
210 struct winsdb_handle *wins_db;
212 /* some configuration */
213 struct {
214 /* the wins config db handle */
215 struct ldb_context *ldb;
217 /* the last wins config db seqnumber we know about */
218 uint64_t seqnumber;
221 * the interval (in secs) till an active record will be marked as RELEASED
223 uint32_t renew_interval;
226 * the interval (in secs) a record remains in RELEASED state,
227 * before it will be marked as TOMBSTONE
228 * (also known as extinction interval)
230 uint32_t tombstone_interval;
233 * the interval (in secs) a record remains in TOMBSTONE state,
234 * before it will be removed from the database.
235 * See also 'tombstone_extra_timeout'.
236 * (also known as extinction timeout)
238 uint32_t tombstone_timeout;
241 * the interval (in secs) a record remains in TOMBSTONE state,
242 * even after 'tombstone_timeout' passes the current timestamp.
243 * this is the minimum uptime of the wrepl service, before
244 * we start delete tombstones. This is to prevent deletion of
245 * tombstones, without replacte them.
247 uint32_t tombstone_extra_timeout;
250 * the interval (in secs) till a replica record will be verified
251 * with the owning wins server
253 uint32_t verify_interval;
256 * the interval (in secs) till a do a database cleanup
258 uint32_t scavenging_interval;
261 * the interval (in secs) to the next periodic processing
262 * (this is the maximun interval)
264 uint32_t periodic_interval;
265 } config;
267 /* all incoming connections */
268 struct wreplsrv_in_connection *in_connections;
270 /* all partners (pull and push) */
271 struct wreplsrv_partner *partners;
274 * this is our local wins_owner entry, this is also in the table list
275 * but we need a pointer to it, because we need to update it on each
276 * query to wreplsrv_find_owner(), as the local records can be added
277 * to the wins.ldb from external tools and the winsserver
279 struct wreplsrv_owner *owner;
281 /* this is a list of each wins_owner we know about in our database */
282 struct wreplsrv_owner *table;
284 /* some stuff for periodic processing */
285 struct {
287 * the timestamp for the next event,
288 * this is the timstamp passed to event_add_timed()
290 struct timeval next_event;
292 /* here we have a reference to the timed event the schedules the periodic stuff */
293 struct tevent_timer *te;
294 } periodic;
296 /* some stuff for scavenging processing */
297 struct {
299 * the timestamp for the next scavenging run,
300 * this is the timstamp passed to event_add_timed()
302 struct timeval next_run;
305 * are we currently inside a scavenging run
307 bool processing;
308 } scavenging;
311 struct socket_context;
312 struct wrepl_name;
313 #include "wrepl_server/wrepl_out_helpers.h"
314 #include "wrepl_server/wrepl_server_proto.h"