2 Unix SMB/Netbios implementation.
4 NBT netbios header - version 2
5 Copyright (C) Andrew Tridgell 1994-1995
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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* NTAS uses 2, NT uses 1, WfWg uses 0 */
24 #define MAINTAIN_LIST 2
25 #define ELECTION_VERSION 1
27 #define MAX_DGRAM_SIZE (80*18+64)
28 #define MIN_DGRAM_SIZE 12
30 #define NMB_QUERY 0x20
31 #define NMB_STATUS 0x21
37 #define NB_ACTIVE 0x04
44 #define NB_FLGMSK 0x60
46 #define REFRESH_TIME (15*60)
48 #define NAME_PERMANENT(p) ((p) & NB_PERM)
49 #define NAME_ACTIVE(p) ((p) & NB_ACTIVE)
50 #define NAME_CONFLICT(p) ((p) & NB_CONFL)
51 #define NAME_DEREG(p) ((p) & NB_DEREG)
52 #define NAME_GROUP(p) ((p) & NB_GROUP)
54 #define NAME_BFLAG(p) (((p) & NB_FLGMSK) == NB_BFLAG)
55 #define NAME_PFLAG(p) (((p) & NB_FLGMSK) == NB_PFLAG)
56 #define NAME_MFLAG(p) (((p) & NB_FLGMSK) == NB_MFLAG)
57 #define NAME__FLAG(p) (((p) & NB_FLGMSK) == NB__FLAG)
59 #define MSBROWSE "\001\002__MSBROWSE__\002"
61 enum name_search { FIND_SELF, FIND_GLOBAL };
62 enum name_source {STATUS_QUERY, LMHOSTS, REGISTER, SELF, DNS, DNSFAIL};
63 enum node_type {B_NODE=0, P_NODE=1, M_NODE=2, NBDD_NODE=3};
64 enum packet_type {NMB_PACKET, DGRAM_PACKET};
67 NAME_STATUS_MASTER_CHECK,
78 /* a netbios name structure */
85 /* this is the structure used for the local netbios name list */
88 struct name_record *next;
89 struct name_record *prev;
94 enum name_source source;
97 /* browse and backup server cache for synchronising browse list */
98 struct browse_cache_record
100 struct browse_cache_record *next;
101 struct browse_cache_record *prev;
111 /* this is used to hold the list of servers in my domain, and is */
112 /* contained within lists of domains */
115 struct server_record *next;
116 struct server_record *prev;
118 struct server_info_struct serv;
122 /* a workgroup structure. it contains a list of servers */
125 struct work_record *next;
126 struct work_record *prev;
128 struct server_record *serverlist;
130 /* work group info */
132 int token; /* used when communicating with backup browsers */
136 time_t lastannounce_time;
137 int announce_interval;
141 BOOL RunningElection;
144 uint32 ElectionCriterion;
147 /* a domain structure. it contains a list of workgroups */
150 struct domain_record *next;
151 struct domain_record *prev;
153 struct work_record *workgrouplist;
155 struct in_addr bcast_ip;
156 struct in_addr mask_ip;
160 /* a resource record */
162 struct nmb_name rr_name;
167 char rdata[MAX_DGRAM_SIZE];
170 /* define a nmb packet. */
179 BOOL recursion_available;
180 BOOL recursion_desired;
192 struct nmb_name question_name;
197 struct res_rec *answers;
198 struct res_rec *nsrecs;
199 struct res_rec *additional;
203 /* initiated name queries recorded in this list to track any responses... */
204 struct name_response_record
206 struct name_response_record *next;
207 struct name_response_record *prev;
210 enum cmd_type cmd_type;
213 struct nmb_name name;
216 struct in_addr to_ip;
222 /* a datagram - this normally contains SMB data in the data[] array */
223 struct dgram_packet {
227 enum node_type node_type;
232 struct in_addr source_ip;
237 struct nmb_name source_name;
238 struct nmb_name dest_name;
240 char data[MAX_DGRAM_SIZE];
243 /* define a structure used to queue packets. this will be a linked
244 list of nmb packets */
247 struct packet_struct *next;
248 struct packet_struct *prev;
253 enum packet_type packet_type;
255 struct nmb_packet nmb;
256 struct dgram_packet dgram;
261 #define AM_MASTER(work) (work->ServerType & SV_TYPE_MASTER_BROWSER)
262 #define AM_BACKUP(work) (work->ServerType & SV_TYPE_BACKUP_BROWSER)
263 #define AM_DOMCTL(work) (work->ServerType & SV_TYPE_DOMAIN_CTRL)
266 /* ids for netbios packet types */
267 #define ANN_HostAnnouncement 1
268 #define ANN_AnnouncementRequest 2
269 #define ANN_Election 8
270 #define ANN_GetBackupListReq 9
271 #define ANN_GetBackupListResp 10
272 #define ANN_BecomeBackup 11
273 #define ANN_DomainAnnouncement 12
274 #define ANN_MasterAnnouncement 13
275 #define ANN_ResetBrowserState 14
276 #define ANN_LocalMasterAnnouncement 15
279 /* broadcast packet announcement intervals, in minutes */
281 /* search for master browsers of workgroups samba knows about,
283 #define CHECK_TIME_MST_BROWSE 5
285 /* request backup browser announcements from other servers */
286 #define CHECK_TIME_ANNOUNCE_BACKUP 15
288 /* request host announcements from other servers: min and max of interval */
289 #define CHECK_TIME_MIN_HOST_ANNCE 3
290 #define CHECK_TIME_MAX_HOST_ANNCE 12
292 /* announce as master to WINS server and any Primary Domain Controllers */
293 #define CHECK_TIME_MST_ANNOUNCE 15