smbd: Simplify an if-condition
[Samba.git] / source3 / nmbd / nmbd.h
blob0a8e345ddaef27fc3043e0c2eb5cc92487934905
1 /*
2 * Unix SMB/CIFS implementation.
3 * NBT netbios routines and daemon - version 2
5 * Copyright (C) Guenther Deschner 2011
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef _NMBD_NMBD_H_
22 #define _NMBD_NMBD_H_
24 #ifndef HAVE_PIPE
25 #define SYNC_DNS 1
26 #endif
28 #include "libsmb/nmblib.h"
30 #define INFO_VERSION "INFO/version"
31 #define INFO_COUNT "INFO/num_entries"
32 #define INFO_ID_HIGH "INFO/id_high"
33 #define INFO_ID_LOW "INFO/id_low"
34 #define ENTRY_PREFIX "ENTRY/"
36 #define PERMANENT_TTL 0
38 /* NTAS uses 2, NT uses 1, WfWg uses 0 */
39 #define MAINTAIN_LIST 2
40 #define ELECTION_VERSION 1
42 #define REFRESH_TIME (15*60)
43 #define NAME_POLL_REFRESH_TIME (5*60)
44 #define NAME_POLL_INTERVAL 15
46 /* Workgroup state identifiers. */
47 #define AM_POTENTIAL_MASTER_BROWSER(work) ((work)->mst_state == MST_POTENTIAL)
48 #define AM_LOCAL_MASTER_BROWSER(work) ((work)->mst_state == MST_BROWSER)
49 #define AM_DOMAIN_MASTER_BROWSER(work) ((work)->dom_state == DOMAIN_MST)
50 #define AM_DOMAIN_MEMBER(work) ((work)->log_state == LOGON_SRV)
52 /* Microsoft browser NetBIOS name. */
53 #define MSBROWSE "\001\002__MSBROWSE__\002"
55 /* Mail slots. */
56 #define BROWSE_MAILSLOT "\\MAILSLOT\\BROWSE"
57 #define NET_LOGON_MAILSLOT "\\MAILSLOT\\NET\\NETLOGON"
58 #define NT_LOGON_MAILSLOT "\\MAILSLOT\\NET\\NTLOGON"
59 #define LANMAN_MAILSLOT "\\MAILSLOT\\LANMAN"
61 /* Samba definitions for find_name_on_subnet(). */
62 #define FIND_ANY_NAME 0
63 #define FIND_SELF_NAME 1
66 * The different name types that can be in namelists.
68 * SELF_NAME should only be on the broadcast and unicast subnets.
69 * LMHOSTS_NAME should only be in the remote_broadcast_subnet.
70 * REGISTER_NAME, DNS_NAME, DNSFAIL_NAME should only be in the wins_server_subnet.
71 * WINS_PROXY_NAME should only be on the broadcast subnets.
72 * PERMANENT_NAME can be on all subnets except remote_broadcast_subnet.
76 enum name_source {LMHOSTS_NAME, REGISTER_NAME, SELF_NAME, DNS_NAME,
77 DNSFAIL_NAME, PERMANENT_NAME, WINS_PROXY_NAME};
79 enum master_state {
80 MST_NONE,
81 MST_POTENTIAL,
82 MST_BACKUP,
83 MST_MSB,
84 MST_BROWSER,
85 MST_UNBECOMING_MASTER
88 enum domain_state {
89 DOMAIN_NONE,
90 DOMAIN_WAIT,
91 DOMAIN_MST
94 enum logon_state {
95 LOGON_NONE,
96 LOGON_WAIT,
97 LOGON_SRV
100 struct subnet_record;
102 struct nmb_data {
103 uint16_t nb_flags; /* Netbios flags. */
104 int num_ips; /* Number of ip entries. */
105 struct in_addr *ip; /* The ip list for this name. */
107 enum name_source source; /* Where the name came from. */
109 time_t death_time; /* The time the record must be removed (do not remove if 0). */
110 time_t refresh_time; /* The time the record should be refreshed. */
112 uint64_t id; /* unique id */
113 struct in_addr wins_ip; /* the address of the wins server this record comes from */
115 int wins_flags; /* similar to the netbios flags but different ! */
118 /* This structure represents an entry in a local netbios name list. */
119 struct name_record {
120 struct name_record *prev, *next;
121 struct subnet_record *subnet;
122 struct nmb_name name; /* The netbios name. */
123 struct nmb_data data; /* The netbios data. */
126 /* Browser cache for synchronising browse lists. */
127 struct browse_cache_record {
128 struct browse_cache_record *prev, *next;
129 unstring lmb_name;
130 unstring work_group;
131 struct in_addr ip;
132 time_t sync_time;
133 time_t death_time; /* The time the record must be removed. */
136 /* used for server information: client, nameserv and ipc */
137 struct server_info_struct {
138 fstring name;
139 uint32_t type;
140 fstring comment;
141 fstring domain; /* used ONLY in ipc.c NOT namework.c */
142 bool server_added; /* used ONLY in ipc.c NOT namework.c */
145 /* This is used to hold the list of servers in my domain, and is
146 contained within lists of domains. */
148 struct server_record {
149 struct server_record *next;
150 struct server_record *prev;
152 struct subnet_record *subnet;
154 struct server_info_struct serv;
155 time_t death_time;
158 /* A workgroup structure. It contains a list of servers. */
159 struct work_record {
160 struct work_record *next;
161 struct work_record *prev;
163 struct subnet_record *subnet;
165 struct server_record *serverlist;
167 /* Stage of development from non-local-master up to local-master browser. */
168 enum master_state mst_state;
170 /* Stage of development from non-domain-master to domain-master browser. */
171 enum domain_state dom_state;
173 /* Stage of development from non-logon-server to logon server. */
174 enum logon_state log_state;
176 /* Work group info. */
177 unstring work_group;
178 int token; /* Used when communicating with backup browsers. */
179 unstring local_master_browser_name; /* Current local master browser. */
181 /* Announce info. */
182 time_t lastannounce_time;
183 int announce_interval;
184 bool needannounce;
186 /* Timeout time for this workgroup. 0 means permanent. */
187 time_t death_time;
189 /* Election info */
190 bool RunningElection;
191 bool needelection;
192 int ElectionCount;
193 uint32_t ElectionCriterion;
195 /* Domain master browser info. Used for efficient syncs. */
196 struct nmb_name dmb_name;
197 struct in_addr dmb_addr;
200 /* typedefs needed to define copy & free functions for userdata. */
201 struct userdata_struct;
203 typedef struct userdata_struct * (*userdata_copy_fn)(struct userdata_struct *);
204 typedef void (*userdata_free_fn)(struct userdata_struct *);
206 /* Structure to define any userdata passed around. */
208 struct userdata_struct {
209 userdata_copy_fn copy_fn;
210 userdata_free_fn free_fn;
211 unsigned int userdata_len;
212 char data[16]; /* 16 is to ensure alignment/padding on all systems */
215 struct response_record;
216 struct packet_struct;
217 struct res_rec;
219 /* typedef to define the function called when this response packet comes in. */
220 typedef void (*response_function)(struct subnet_record *, struct response_record *,
221 struct packet_struct *);
223 /* typedef to define the function called when this response record times out. */
224 typedef void (*timeout_response_function)(struct subnet_record *,
225 struct response_record *);
227 /* typedef to define the function called when the request that caused this
228 response record to be created is successful. */
229 typedef void (*success_function)(struct subnet_record *, struct userdata_struct *, ...);
231 /* typedef to define the function called when the request that caused this
232 response record to be created is unsuccessful. */
233 typedef void (*fail_function)(struct subnet_record *, struct response_record *, ...);
235 /* List of typedefs for success and fail functions of the different query
236 types. Used to catch any compile time prototype errors. */
238 typedef void (*register_name_success_function)( struct subnet_record *,
239 struct userdata_struct *,
240 struct nmb_name *,
241 uint16_t,
242 int,
243 struct in_addr);
244 typedef void (*register_name_fail_function)( struct subnet_record *,
245 struct response_record *,
246 struct nmb_name *);
248 typedef void (*release_name_success_function)( struct subnet_record *,
249 struct userdata_struct *,
250 struct nmb_name *,
251 struct in_addr);
252 typedef void (*release_name_fail_function)( struct subnet_record *,
253 struct response_record *,
254 struct nmb_name *);
256 typedef void (*refresh_name_success_function)( struct subnet_record *,
257 struct userdata_struct *,
258 struct nmb_name *,
259 uint16_t,
260 int,
261 struct in_addr);
262 typedef void (*refresh_name_fail_function)( struct subnet_record *,
263 struct response_record *,
264 struct nmb_name *);
266 typedef void (*query_name_success_function)( struct subnet_record *,
267 struct userdata_struct *,
268 struct nmb_name *,
269 struct in_addr,
270 struct res_rec *answers);
272 typedef void (*query_name_fail_function)( struct subnet_record *,
273 struct response_record *,
274 struct nmb_name *,
275 int);
277 typedef void (*node_status_success_function)( struct subnet_record *,
278 struct userdata_struct *,
279 struct res_rec *,
280 struct in_addr);
281 typedef void (*node_status_fail_function)( struct subnet_record *,
282 struct response_record *);
284 /* Initiated name queries are recorded in this list to track any responses. */
286 struct response_record {
287 struct response_record *next;
288 struct response_record *prev;
290 uint16_t response_id;
292 /* Callbacks for packets received or not. */
293 response_function resp_fn;
294 timeout_response_function timeout_fn;
296 /* Callbacks for the request succeeding or not. */
297 success_function success_fn;
298 fail_function fail_fn;
300 struct packet_struct *packet;
302 struct userdata_struct *userdata;
304 int num_msgs;
306 time_t repeat_time;
307 time_t repeat_interval;
308 int repeat_count;
310 /* Recursion protection. */
311 bool in_expiration_processing;
314 /* A subnet structure. It contains a list of workgroups and netbios names. */
317 B nodes will have their own, totally separate subnet record, with their
318 own netbios name set. These do NOT interact with other subnet records'
319 netbios names.
322 enum subnet_type {
323 NORMAL_SUBNET = 0, /* Subnet listed in interfaces list. */
324 UNICAST_SUBNET = 1, /* Subnet for unicast packets. */
325 REMOTE_BROADCAST_SUBNET = 2, /* Subnet for remote broadcasts. */
326 WINS_SERVER_SUBNET = 3 /* Only created if we are a WINS server. */
329 struct subnet_record {
330 struct subnet_record *next;
331 struct subnet_record *prev;
333 char *subnet_name; /* For Debug identification. */
334 enum subnet_type type; /* To catagorize the subnet. */
336 struct work_record *workgrouplist; /* List of workgroups. */
337 struct name_record *namelist; /* List of netbios names. */
338 struct response_record *responselist; /* List of responses expected. */
340 bool namelist_changed;
341 bool work_changed;
343 struct in_addr bcast_ip;
344 struct in_addr mask_ip;
345 struct in_addr myip;
346 int nmb_sock; /* socket to listen for unicast 137. */
347 int nmb_bcast; /* socket to listen for broadcast 137. */
348 int dgram_sock; /* socket to listen for unicast 138. */
349 int dgram_bcast; /* socket to listen for broadcast 138. */
352 /* Broadcast packet announcement intervals, in minutes. */
354 /* Attempt to add domain logon and domain master names. */
355 #define CHECK_TIME_ADD_DOM_NAMES 5
357 /* Search for master browsers of workgroups samba knows about,
358 except default. */
359 #define CHECK_TIME_MST_BROWSE 5
361 /* Request backup browser announcements from other servers. */
362 #define CHECK_TIME_ANNOUNCE_BACKUP 15
364 /* Request host announcements from other servers: min and max of interval. */
365 #define CHECK_TIME_MIN_HOST_ANNCE 3
366 #define CHECK_TIME_MAX_HOST_ANNCE 12
368 /* Announce as master to WINS server and any Primary Domain Controllers. */
369 #define CHECK_TIME_MST_ANNOUNCE 15
371 /* Time between syncs from domain master browser to local master browsers. */
372 #define CHECK_TIME_DMB_TO_LMB_SYNC 15
374 /* Do all remote announcements this often. */
375 #define REMOTE_ANNOUNCE_INTERVAL 180
377 /* what is the maximum period between name refreshes. Note that this only
378 affects non-permanent self names (in seconds) */
379 #define MAX_REFRESH_TIME (60*20)
381 /* The Extinction interval: 4 days, time a node will stay in released state */
382 #define EXTINCTION_INTERVAL (4*24*60*60)
384 /* The Extinction time-out: 1 day, time a node will stay in deleted state */
385 #define EXTINCTION_TIMEOUT (24*60*60)
387 /* Macro's to enumerate subnets either with or without
388 the UNICAST subnet. */
390 extern struct subnet_record *subnetlist;
391 extern struct subnet_record *unicast_subnet;
392 extern struct subnet_record *wins_server_subnet;
393 extern struct subnet_record *remote_broadcast_subnet;
395 #define FIRST_SUBNET subnetlist
396 #define NEXT_SUBNET_EXCLUDING_UNICAST(x) ((x)->next)
397 #define NEXT_SUBNET_INCLUDING_UNICAST(x) (get_next_subnet_maybe_unicast((x)))
399 /* wins replication record used between nmbd and wrepld */
400 typedef struct _WINS_RECORD {
401 char name[17];
402 char type;
403 int nb_flags;
404 int wins_flags;
405 uint64_t id;
406 int num_ips;
407 struct in_addr ip[25];
408 struct in_addr wins_ip;
409 } WINS_RECORD;
411 #include "nmbd/nmbd_proto.h"
413 #define NMBD_WAIT_INTERFACES_TIME_USEC (250 * 1000)
415 /****************************************************************************
416 true if two IPv4 addresses are equal
417 ****************************************************************************/
419 #define ip_equal_v4(ip1,ip2) ((ip1).s_addr == (ip2).s_addr)
421 #endif /* _NMBD_NMBD_H_ */