r11052: bring samba4 uptodate with the samba4-winsrepl branch,
[tprouty/samba.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 };
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
47         /* our global service context */
48         struct wreplsrv_service *service;
49
50         /*
51          * the partner that connects us,
52          * can be NULL, when we got a connection
53          * from an unknown address
54          */
55         struct wreplsrv_partner *partner;
56
57         /*
58          * we need to take care of our own ip address,
59          * as this is the WINS-Owner ID the peer expect
60          * from us.
61          */
62         const char *our_ip;
63
64         /* keep track of the assoc_ctx's */
65         struct {
66                 BOOL stopped;
67                 uint32_t our_ctx;
68                 uint32_t peer_ctx;
69         } assoc_ctx;
70
71         /* the partial input on the connection */
72         DATA_BLOB partial;
73         size_t partial_read;
74
75         /*
76          * are we currently processing a request?
77          * this prevents loops, with half async code
78          */
79         BOOL processing;
80
81         /*
82          * if this is set we no longer accept incoming packets
83          * and terminate the connection after we have send all packets
84          */
85         BOOL terminate;
86
87         /* the list of outgoing DATA_BLOB's that needs to be send */
88         struct data_blob_list_item *send_queue;
89 };
90
91 /*
92   state of an outcoming wrepl connection
93 */
94 struct wreplsrv_out_connection {
95         /* our global service context */
96         struct wreplsrv_service *service;
97
98         /*
99          * the partner that connects us,
100          * can be NULL, when we got a connection
101          * from an unknown address
102          */
103         struct wreplsrv_partner *partner;
104
105         /* keep track of the assoc_ctx's */
106         struct {
107                 uint32_t our_ctx;
108                 uint32_t peer_ctx;
109         } assoc_ctx;
110
111         /* 
112          * the client socket to the partner,
113          * NULL if not yet connected
114          */
115         struct wrepl_socket *sock;
116 };
117
118 enum winsrepl_partner_type {
119         WINSREPL_PARTNER_NONE = 0x0,
120         WINSREPL_PARTNER_PULL = 0x1,
121         WINSREPL_PARTNER_PUSH = 0x2,
122         WINSREPL_PARTNER_BOTH = (WINSREPL_PARTNER_PULL | WINSREPL_PARTNER_PUSH)
123 };
124
125 #define WINSREPL_DEFAULT_PULL_INTERVAL (30*60)
126 #define WINSREPL_DEFAULT_PULL_RETRY_INTERVAL (30)
127
128 /*
129  this represents one of our configured partners
130 */
131 struct wreplsrv_partner {
132         struct wreplsrv_partner *prev,*next;
133
134         /* our global service context */
135         struct wreplsrv_service *service;
136
137         /* the netbios name of the partner, mostly just for debugging */
138         const char *name;
139
140         /* the ip-address of the partner */
141         const char *address;
142
143         /* 
144          * as wins partners identified by ip-address, we need to use a specific source-ip
145          *  when we want to connect to the partner
146          */
147         const char *our_address;
148
149         /* the type of the partner, pull, push or both */
150         enum winsrepl_partner_type type;
151
152         /* pull specific options */
153         struct {
154                 /* the interval between 2 pull replications to the partner */
155                 uint32_t interval;
156
157                 /* the retry_interval if a pull cycle failed to the partner */
158                 uint32_t retry_interval;
159
160                 /* the error count till the last success */
161                 uint32_t error_count;
162
163                 /* the status of the last pull cycle */
164                 NTSTATUS last_status;
165
166                 /* this is a list of each wins_owner the partner knows about */
167                 struct wreplsrv_owner *table;
168
169                 /* the outgoing connection to the partner */
170                 struct wreplsrv_out_connection *wreplconn;
171
172                 /* the current pending pull cycle request */
173                 struct composite_context *creq;
174
175                 /* the pull cycle io params */
176                 struct wreplsrv_pull_cycle_io *cycle_io;
177
178                 /* the current timed_event to the next pull cycle */
179                 struct timed_event *te;
180         } pull;
181
182         /* push specific options */
183         struct {
184                 /* change count till push notification */
185                 uint32_t change_count;
186
187                 /* the status of the last push cycle */
188                 NTSTATUS last_status;
189
190                 /* the outgoing connection to the partner */
191                 struct wreplsrv_out_connection *wreplconn;
192
193                 /* the current push notification */
194                 struct composite_context *creq;
195
196                 /* the pull cycle io params */
197                 struct wreplsrv_push_notify_io *notify_io;
198
199                 /* the current timed_event to the next push notify */
200                 struct timed_event *te;
201         } push;
202 };
203
204 struct wreplsrv_owner {
205         struct wreplsrv_owner *prev,*next;
206
207         /* this hold the owner_id (address), min_version, max_version and partner_type */
208         struct wrepl_wins_owner owner;
209
210         /* can be NULL if this owner isn't a configure partner */
211         struct wreplsrv_partner *partner; 
212 };
213
214 /*
215   state of the whole wrepl service
216 */
217 struct wreplsrv_service {
218         /* the whole wrepl service is in one task */
219         struct task_server *task;
220
221         /* the winsdb handle */
222         struct ldb_context *wins_db;
223
224         /* all incoming connections */
225         struct wreplsrv_in_connection *in_connections;
226
227         /* all partners (pull and push) */
228         struct wreplsrv_partner *partners;
229
230         /* this is a list of each wins_owner we know about in our database */
231         struct wreplsrv_owner *table;
232 };