278b15fbb7ceb7de97058b4a8b13014d08ca1290
[garming/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 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         struct wreplsrv_partner *partner;
96 };
97
98 enum winsrepl_partner_type {
99         WINSREPL_PARTNER_PULL = 0x1,
100         WINSREPL_PARTNER_PUSH = 0x2,
101         WINSREPL_PARTNER_BOTH = (WINSREPL_PARTNER_PULL | WINSREPL_PARTNER_PUSH)
102 };
103
104 #define WINSREPL_DEFAULT_PULL_INTERVAL (30*60)
105
106 /*
107  this represents one of our configured partners
108 */
109 struct wreplsrv_partner {
110         struct wreplsrv_partner *prev,*next;
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                 /* this is a list of each wins_owner the partner knows about */
133                 struct wreplsrv_owner *table;
134
135                 /* the outgoing connection to the partner */
136                 struct wreplsrv_out_connection *wreplconn;
137         } pull;
138 };
139
140 struct wreplsrv_owner {
141         struct wreplsrv_owner *prev,*next;
142
143         /* this hold the owner_id (address), min_version, max_version and partner_type */
144         struct wrepl_wins_owner owner;
145
146         /* can be NULL if this owner isn't a configure partner */
147         struct wreplsrv_partner *partner; 
148 };
149
150 /*
151   state of the whole wrepl service
152 */
153 struct wreplsrv_service {
154         /* the whole wrepl service is in one task */
155         struct task_server *task;
156
157         /* the winsdb handle */
158         struct ldb_context *wins_db;
159
160         /* all incoming connections */
161         struct wreplsrv_in_connection *in_connections;
162
163         /* all partners (pull and push) */
164         struct wreplsrv_partner *partners;
165
166         /* this is a list of each wins_owner we know about in our database */
167         struct wreplsrv_owner *table;
168 };