1 #ifndef _NAMESERV_H_
2 #define _NAMESERV_H_
3
4
5
6
7
8
9 #define PERMANENT_TTL 0
10
11
12 #define MAINTAIN_LIST 2
13 #define ELECTION_VERSION 1
14
15 #define MAX_DGRAM_SIZE (576)
16 #define MIN_DGRAM_SIZE 12
17
18
19
20
21
22 enum netbios_reply_type_code
23 { NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH,
24 NMB_REL, NMB_WAIT_ACK, NMB_MULTIHOMED_REG,
25 WINS_REG, WINS_QUERY
26 };
27
28
29
30 #define QUESTION_TYPE_NB_QUERY 0x20
31 #define QUESTION_TYPE_NB_STATUS 0x21
32
33
34 #define QUESTION_CLASS_IN 0x1
35
36
37 #define NMB_NAME_QUERY_OPCODE 0x0
38 #define NMB_NAME_REG_OPCODE 0x05
39 #define NMB_NAME_RELEASE_OPCODE 0x06
40 #define NMB_WACK_OPCODE 0x07
41
42
43 #define NMB_NAME_REFRESH_OPCODE_8 0x08
44 #define NMB_NAME_REFRESH_OPCODE_9 0x09
45 #define NMB_NAME_MULTIHOMED_REG_OPCODE 0x0F
46
47
48
49
50 #define RR_TYPE_A 0x1
51 #define RR_TYPE_NS 0x2
52 #define RR_TYPE_NULL 0xA
53 #define RR_TYPE_NB 0x20
54 #define RR_TYPE_NBSTAT 0x21
55
56
57 #define RR_CLASS_IN 0x1
58
59
60 #define NB_GROUP 0x80
61 #define NB_PERM 0x02
62 #define NB_ACTIVE 0x04
63 #define NB_CONFL 0x08
64 #define NB_DEREG 0x10
65 #define NB_BFLAG 0x00
66 #define NB_PFLAG 0x20
67 #define NB_MFLAG 0x40
68 #define NB_HFLAG 0x60
69 #define NB_NODETYPEMASK 0x60
70
71 #define NB_FLGMSK 0xE0
72
73
74 #define NAME_GROUP(p) ((p)->data.nb_flags & NB_GROUP)
75 #define NAME_BFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_BFLAG)
76 #define NAME_PFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_PFLAG)
77 #define NAME_MFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_MFLAG)
78 #define NAME_HFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_HFLAG)
79
80
81 #define NAME_IS_ACTIVE(p) ((p)->data.nb_flags & NB_ACTIVE)
82 #define NAME_IN_CONFLICT(p) ((p)->data.nb_flags & NB_CONFL)
83 #define NAME_IS_DEREGISTERING(p) ((p)->data.nb_flags & NB_DEREG)
84
85
86 #define FMT_ERR 0x1
87 #define SRV_ERR 0x2
88 #define NAM_ERR 0x3
89 #define IMP_ERR 0x4
90 #define RFS_ERR 0x5
91 #define ACT_ERR 0x6
92 #define CFT_ERR 0x7
93
94 #define REFRESH_TIME (15*60)
95 #define NAME_POLL_REFRESH_TIME (5*60)
96 #define NAME_POLL_INTERVAL 15
97
98
99 #define AM_POTENTIAL_MASTER_BROWSER(work) ((work)->mst_state == MST_POTENTIAL)
100 #define AM_LOCAL_MASTER_BROWSER(work) ((work)->mst_state == MST_BROWSER)
101 #define AM_DOMAIN_MASTER_BROWSER(work) ((work)->dom_state == DOMAIN_MST)
102 #define AM_DOMAIN_MEMBER(work) ((work)->log_state == LOGON_SRV)
103
104
105 #define MSBROWSE "\001\002__MSBROWSE__\002"
106
107
108 #define BROWSE_MAILSLOT "\\MAILSLOT\\BROWSE"
109 #define NET_LOGON_MAILSLOT "\\MAILSLOT\\NET\\NETLOGON"
110 #define NT_LOGON_MAILSLOT "\\MAILSLOT\\NET\\NTLOGON"
111 #define LANMAN_MAILSLOT "\\MAILSLOT\\LANMAN"
112
113
114 #define FIND_ANY_NAME 0
115 #define FIND_SELF_NAME 1
116
117
118
119
120
121
122
123
124
125
126
127
128 enum name_source
129 { LMHOSTS_NAME, REGISTER_NAME, SELF_NAME, DNS_NAME,
130 DNSFAIL_NAME, PERMANENT_NAME, WINS_PROXY_NAME
131 };
132 enum node_type
133 { B_NODE = 0, P_NODE = 1, M_NODE = 2, NBDD_NODE = 3 };
134 enum packet_type
135 { NMB_PACKET, DGRAM_PACKET };
136
137 enum master_state
138 {
139 MST_NONE,
140 MST_POTENTIAL,
141 MST_BACKUP,
142 MST_MSB,
143 MST_BROWSER,
144 MST_UNBECOMING_MASTER
145 };
146
147 enum domain_state
148 {
149 DOMAIN_NONE,
150 DOMAIN_WAIT,
151 DOMAIN_MST
152 };
153
154 enum logon_state
155 {
156 LOGON_NONE,
157 LOGON_WAIT,
158 LOGON_SRV
159 };
160
161 struct subnet_record;
162
163 struct nmb_data
164 {
165 uint16 nb_flags;
166 int num_ips;
167 struct in_addr *ip;
168
169 enum name_source source;
170
171 time_t death_time;
172 time_t refresh_time;
173 };
174
175
176
177
178 struct server_record
179 {
180 struct server_record *next;
181 struct server_record *prev;
182
183 struct subnet_record *subnet;
184
185 struct server_info_struct serv;
186 time_t death_time;
187 };
188
189
190 struct work_record
191 {
192 struct work_record *next;
193 struct work_record *prev;
194
195 struct subnet_record *subnet;
196
197 struct server_record *serverlist;
198
199
200 enum master_state mst_state;
201
202
203 enum domain_state dom_state;
204
205
206 enum logon_state log_state;
207
208
209 fstring work_group;
210 int token;
211 fstring local_master_browser_name;
212
213
214 time_t lastannounce_time;
215 int announce_interval;
216 BOOL needannounce;
217
218
219 time_t death_time;
220
221
222 BOOL RunningElection;
223 BOOL needelection;
224 int ElectionCount;
225 uint32 ElectionCriterion;
226
227
228 struct nmb_name dmb_name;
229 struct in_addr dmb_addr;
230 };
231
232
233 struct userdata_struct;
234
235 typedef struct userdata_struct *(*userdata_copy_fn) (struct userdata_struct *);
236 typedef void (*userdata_free_fn) (struct userdata_struct *);
237
238
239
240 struct userdata_struct
241 {
242 userdata_copy_fn copy_fn;
243 userdata_free_fn free_fn;
244 unsigned int userdata_len;
245 char data[16];
246 };
247
248 struct response_record;
249 struct packet_struct;
250 struct res_rec;
251
252
253 typedef void (*response_function) (struct subnet_record *, struct response_record *,
254 struct packet_struct *);
255
256
257 typedef void (*timeout_response_function) (struct subnet_record *, struct response_record *);
258
259
260
261 typedef void (*success_function) (struct subnet_record *, struct userdata_struct *, ...);
262
263
264
265 typedef void (*fail_function) (struct subnet_record *, struct response_record *, ...);
266
267
268
269
270 typedef void (*register_name_success_function) (struct subnet_record *,
271 struct userdata_struct *,
272 struct nmb_name *, uint16, int, struct in_addr);
273 typedef void (*register_name_fail_function) (struct subnet_record *,
274 struct response_record *, struct nmb_name *);
275
276 typedef void (*release_name_success_function) (struct subnet_record *,
277 struct userdata_struct *,
278 struct nmb_name *, struct in_addr);
279 typedef void (*release_name_fail_function) (struct subnet_record *,
280 struct response_record *, struct nmb_name *);
281
282 typedef void (*refresh_name_success_function) (struct subnet_record *,
283 struct userdata_struct *,
284 struct nmb_name *, uint16, int, struct in_addr);
285 typedef void (*refresh_name_fail_function) (struct subnet_record *,
286 struct response_record *, struct nmb_name *);
287
288 typedef void (*query_name_success_function) (struct subnet_record *,
289 struct userdata_struct *,
290 struct nmb_name *,
291 struct in_addr, struct res_rec * answers);
292
293 typedef void (*query_name_fail_function) (struct subnet_record *,
294 struct response_record *, struct nmb_name *, int);
295
296 typedef void (*node_status_success_function) (struct subnet_record *,
297 struct userdata_struct *,
298 struct res_rec *, struct in_addr);
299 typedef void (*node_status_fail_function) (struct subnet_record *, struct response_record *);
300
301
302
303 struct response_record
304 {
305 struct response_record *next;
306 struct response_record *prev;
307
308 uint16 response_id;
309
310
311 response_function resp_fn;
312 timeout_response_function timeout_fn;
313
314
315 success_function success_fn;
316 fail_function fail_fn;
317
318 struct packet_struct *packet;
319
320 struct userdata_struct *userdata;
321
322 int num_msgs;
323
324 time_t repeat_time;
325 time_t repeat_interval;
326 int repeat_count;
327
328
329 BOOL in_expiration_processing;
330 };
331
332
333
334
335
336
337
338
339
340 enum subnet_type
341 {
342 NORMAL_SUBNET = 0,
343 UNICAST_SUBNET = 1,
344 REMOTE_BROADCAST_SUBNET = 2,
345 WINS_SERVER_SUBNET = 3
346 };
347
348
349 struct res_rec
350 {
351 struct nmb_name rr_name;
352 int rr_type;
353 int rr_class;
354 int ttl;
355 int rdlength;
356 char rdata[MAX_DGRAM_SIZE];
357 };
358
359
360 struct nmb_packet
361 {
362 struct
363 {
364 int name_trn_id;
365 int opcode;
366 BOOL response;
367 struct
368 {
369 BOOL bcast;
370 BOOL recursion_available;
371 BOOL recursion_desired;
372 BOOL trunc;
373 BOOL authoritative;
374 } nm_flags;
375 int rcode;
376 int qdcount;
377 int ancount;
378 int nscount;
379 int arcount;
380 } header;
381
382 struct
383 {
384 struct nmb_name question_name;
385 int question_type;
386 int question_class;
387 } question;
388
389 struct res_rec *answers;
390 struct res_rec *nsrecs;
391 struct res_rec *additional;
392 };
393
394
395
396
397 struct dgram_packet
398 {
399 struct
400 {
401 int msg_type;
402 struct
403 {
404 enum node_type node_type;
405 BOOL first;
406 BOOL more;
407 } flags;
408 int dgm_id;
409 struct in_addr source_ip;
410 int source_port;
411 int dgm_length;
412 int packet_offset;
413 } header;
414 struct nmb_name source_name;
415 struct nmb_name dest_name;
416 int datasize;
417 char data[MAX_DGRAM_SIZE];
418 };
419
420
421
422
423 struct packet_struct
424 {
425 struct packet_struct *next;
426 struct packet_struct *prev;
427 BOOL locked;
428 struct in_addr ip;
429 int port;
430 int fd;
431 time_t timestamp;
432 enum packet_type packet_type;
433 union
434 {
435 struct nmb_packet nmb;
436 struct dgram_packet dgram;
437 } packet;
438 };
439
440
441
442 #define QUERYFORPDC 7
443 #define QUERYFORPDC_R 12
444 #define SAMLOGON 18
445 #define SAMLOGON_R 19
446
447
448
449
450 #define ANN_HostAnnouncement 1
451 #define ANN_AnnouncementRequest 2
452 #define ANN_Election 8
453 #define ANN_GetBackupListReq 9
454 #define ANN_GetBackupListResp 10
455 #define ANN_BecomeBackup 11
456 #define ANN_DomainAnnouncement 12
457 #define ANN_MasterAnnouncement 13
458 #define ANN_ResetBrowserState 14
459 #define ANN_LocalMasterAnnouncement 15
460
461
462
463
464
465 #define CHECK_TIME_ADD_DOM_NAMES 5
466
467
468
469 #define CHECK_TIME_MST_BROWSE 5
470
471
472 #define CHECK_TIME_ANNOUNCE_BACKUP 15
473
474
475 #define CHECK_TIME_MIN_HOST_ANNCE 3
476 #define CHECK_TIME_MAX_HOST_ANNCE 12
477
478
479 #define CHECK_TIME_MST_ANNOUNCE 15
480
481
482 #define CHECK_TIME_DMB_TO_LMB_SYNC 15
483
484
485 #define REMOTE_ANNOUNCE_INTERVAL 180
486
487
488
489 #define MAX_REFRESH_TIME (60*20)
490
491
492
493
494 extern struct subnet_record *subnetlist;
495 extern struct subnet_record *unicast_subnet;
496 extern struct subnet_record *wins_server_subnet;
497 extern struct subnet_record *remote_broadcast_subnet;
498
499 #define FIRST_SUBNET subnetlist
500 #define NEXT_SUBNET_EXCLUDING_UNICAST(x) ((x)->next)
501 #define NEXT_SUBNET_INCLUDING_UNICAST(x) (get_next_subnet_maybe_unicast((x)))
502
503
504 enum state_type
505 { TEST };
506 #endif