summaryrefslogtreecommitdiff
path: root/source4/wrepl_server/wrepl_server.h
blob: 63603c823dc21050a0830af8815158c3bf21d12c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/* 
   Unix SMB/CIFS implementation.
   
   WINS Replication server
   
   Copyright (C) Stefan Metzmacher	2005
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

struct wreplsrv_service;
struct wreplsrv_in_connection;
struct wreplsrv_out_connection;
struct wreplsrv_partner;

#define WREPLSRV_VALID_ASSOC_CTX	0x12345678
#define WREPLSRV_INVALID_ASSOC_CTX	0x0000000a

/*
  state of an incoming wrepl call
*/
struct wreplsrv_in_call {
	struct wreplsrv_in_connection *wreplconn;
	struct wrepl_packet req_packet;
	struct wrepl_packet rep_packet;
};

/*
  state of an incoming wrepl connection
*/
struct wreplsrv_in_connection {
	struct wreplsrv_in_connection *prev,*next;
	struct stream_connection *conn;

	/* our global service context */
	struct wreplsrv_service *service;

	/*
	 * the partner that connects us,
	 * can be NULL, when we got a connection
	 * from an unknown address
	 */
	struct wreplsrv_partner *partner;

	/*
	 * we need to take care of our own ip address,
	 * as this is the WINS-Owner ID the peer expect
	 * from us.
	 */
	const char *our_ip;

	/* keep track of the assoc_ctx's */
	struct {
		BOOL stopped;
		uint32_t our_ctx;
		uint32_t peer_ctx;
	} assoc_ctx;

	/* the partial input on the connection */
	DATA_BLOB partial;
	size_t partial_read;

	/*
	 * are we currently processing a request?
	 * this prevents loops, with half async code
	 */
	BOOL processing;

	/*
	 * if this is set we no longer accept incoming packets
	 * and terminate the connection after we have send all packets
	 */
	BOOL terminate;

	/* the list of outgoing DATA_BLOB's that needs to be send */
	struct data_blob_list_item *send_queue;
};

/*
  state of an outcoming wrepl connection
*/
struct wreplsrv_out_connection {
	/* our global service context */
	struct wreplsrv_service *service;

	/*
	 * the partner that connects us,
	 * can be NULL, when we got a connection
	 * from an unknown address
	 */
	struct wreplsrv_partner *partner;

	/* keep track of the assoc_ctx's */
	struct {
		uint32_t our_ctx;
		uint32_t peer_ctx;
	} assoc_ctx;

	/* 
	 * the client socket to the partner,
	 * NULL if not yet connected
	 */
	struct wrepl_socket *sock;
};

enum winsrepl_partner_type {
	WINSREPL_PARTNER_NONE = 0x0,
	WINSREPL_PARTNER_PULL = 0x1,
	WINSREPL_PARTNER_PUSH = 0x2,
	WINSREPL_PARTNER_BOTH = (WINSREPL_PARTNER_PULL | WINSREPL_PARTNER_PUSH)
};

#define WINSREPL_DEFAULT_PULL_INTERVAL (30*60)
#define WINSREPL_DEFAULT_PULL_RETRY_INTERVAL (30)

/*
 this represents one of our configured partners
*/
struct wreplsrv_partner {
	struct wreplsrv_partner *prev,*next;

	/* our global service context */
	struct wreplsrv_service *service;

	/* the netbios name of the partner, mostly just for debugging */
	const char *name;

	/* the ip-address of the partner */
	const char *address;

	/* 
	 * as wins partners identified by ip-address, we need to use a specific source-ip
	 *  when we want to connect to the partner
	 */
	const char *our_address;

	/* the type of the partner, pull, push or both */
	enum winsrepl_partner_type type;

	/* pull specific options */
	struct {
		/* the interval between 2 pull replications to the partner */
		uint32_t interval;

		/* the retry_interval if a pull cycle failed to the partner */
		uint32_t retry_interval;

		/* the error count till the last success */
		uint32_t error_count;

		/* the status of the last pull cycle */
		NTSTATUS last_status;

		/* this is a list of each wins_owner the partner knows about */
		struct wreplsrv_owner *table;

		/* the outgoing connection to the partner */
		struct wreplsrv_out_connection *wreplconn;

		/* the current pending pull cycle request */
		struct composite_context *creq;

		/* the pull cycle io params */
		struct wreplsrv_pull_cycle_io *cycle_io;

		/* the current timed_event to the next pull cycle */
		struct timed_event *te;
	} pull;

	/* push specific options */
	struct {
		/* change count till push notification */
		uint32_t change_count;

		/* the status of the last push cycle */
		NTSTATUS last_status;

		/* the outgoing connection to the partner */
		struct wreplsrv_out_connection *wreplconn;

		/* the current push notification */
		struct composite_context *creq;

		/* the pull cycle io params */
		struct wreplsrv_push_notify_io *notify_io;

		/* the current timed_event to the next push notify */
		struct timed_event *te;
	} push;
};

struct wreplsrv_owner {
	struct wreplsrv_owner *prev,*next;

	/* this hold the owner_id (address), min_version, max_version and partner_type */
	struct wrepl_wins_owner owner;

	/* can be NULL if this owner isn't a configure partner */
	struct wreplsrv_partner *partner; 
};

/*
  state of the whole wrepl service
*/
struct wreplsrv_service {
	/* the whole wrepl service is in one task */
	struct task_server *task;

	/* the winsdb handle */
	struct ldb_context *wins_db;

	/* all incoming connections */
	struct wreplsrv_in_connection *in_connections;

	/* all partners (pull and push) */
	struct wreplsrv_partner *partners;

	/* this is a list of each wins_owner we know about in our database */
	struct wreplsrv_owner *table;
};