Describe implication of upstream ICU-22610
[Samba.git] / source3 / include / nameserv.h
blob51efe82d06114433324921ac6631941228bf01d2
1 #ifndef _NAMESERV_H_
2 #define _NAMESERV_H_
3 /*
4 Unix SMB/CIFS implementation.
5 NBT netbios header - version 2
6 Copyright (C) Andrew Tridgell 1994-1998
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 3 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #define MAX_DGRAM_SIZE (576) /* tcp/ip datagram limit is 576 bytes */
24 #define MIN_DGRAM_SIZE 12
26 /*********************************************************
27 Types of reply packet.
28 **********************************************************/
30 enum netbios_reply_type_code { NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH,
31 NMB_REL, NMB_WAIT_ACK, NMB_MULTIHOMED_REG,
32 WINS_REG, WINS_QUERY };
34 /* From rfc1002, 4.2.1.2 */
35 /* Question types. */
36 #define QUESTION_TYPE_NB_QUERY 0x20
37 #define QUESTION_TYPE_NB_STATUS 0x21
39 /* Question class */
40 #define QUESTION_CLASS_IN 0x1
42 /* Opcode definitions */
43 #define NMB_NAME_QUERY_OPCODE 0x0
44 #define NMB_NAME_REG_OPCODE 0x05 /* see rfc1002.txt 4.2.2,3,5,6,7,8 */
45 #define NMB_NAME_RELEASE_OPCODE 0x06 /* see rfc1002.txt 4.2.9,10,11 */
46 #define NMB_WACK_OPCODE 0x07 /* see rfc1002.txt 4.2.16 */
47 /* Ambiguity in rfc1002 about which of these is correct. */
48 /* WinNT uses 8 by default but can be made to use 9. */
49 #define NMB_NAME_REFRESH_OPCODE_8 0x08 /* see rfc1002.txt 4.2.4 */
50 #define NMB_NAME_REFRESH_OPCODE_9 0x09 /* see rfc1002.txt 4.2.4 */
51 #define NMB_NAME_MULTIHOMED_REG_OPCODE 0x0F /* Invented by Microsoft. */
53 /* XXXX what about all the other types?? 0x1, 0x2, 0x3, 0x4, 0x8? */
55 /* Resource record types. rfc1002 4.2.1.3 */
56 #define RR_TYPE_A 0x1
57 #define RR_TYPE_NS 0x2
58 #define RR_TYPE_NULL 0xA
59 #define RR_TYPE_NB 0x20
60 #define RR_TYPE_NBSTAT 0x21
62 /* Resource record class. */
63 #define RR_CLASS_IN 0x1
65 /* NetBIOS flags */
66 #define NB_GROUP 0x80
67 #define NB_PERM 0x02
68 #define NB_ACTIVE 0x04
69 #define NB_CONFL 0x08
70 #define NB_DEREG 0x10
71 #define NB_BFLAG 0x00 /* Broadcast node type. */
72 #define NB_PFLAG 0x20 /* Point-to-point node type. */
73 #define NB_MFLAG 0x40 /* Mixed bcast & p-p node type. */
74 #define NB_HFLAG 0x60 /* Microsoft 'hybrid' node type. */
75 #define NB_NODETYPEMASK 0x60
76 /* Mask applied to outgoing NetBIOS flags. */
77 #define NB_FLGMSK 0xE0
79 /* The wins flags. Looks like the nbflags ! */
80 #define WINS_UNIQUE 0x00 /* Unique record */
81 #define WINS_NGROUP 0x01 /* Normal Group eg: 1B */
82 #define WINS_SGROUP 0x02 /* Special Group eg: 1C */
83 #define WINS_MHOMED 0x03 /* MultiHomed */
85 #define WINS_ACTIVE 0x00 /* active record */
86 #define WINS_RELEASED 0x04 /* released record */
87 #define WINS_TOMBSTONED 0x08 /* tombstoned record */
88 #define WINS_DELETED 0x0C /* deleted record */
90 #define WINS_STATE_MASK 0x0C
92 #define WINS_LOCAL 0x00 /* local record */
93 #define WINS_REMOTE 0x10 /* remote record */
95 #define WINS_BNODE 0x00 /* Broadcast node */
96 #define WINS_PNODE 0x20 /* PtP node */
97 #define WINS_MNODE 0x40 /* Mixed node */
98 #define WINS_HNODE 0x60 /* Hybrid node */
100 #define WINS_NONSTATIC 0x00 /* dynamic record */
101 #define WINS_STATIC 0x80 /* static record */
103 #define WINS_STATE_ACTIVE(p) (((p)->data.wins_flags & WINS_STATE_MASK) == WINS_ACTIVE)
106 /* NetBIOS flag identifier. */
107 #define NAME_GROUP(p) ((p)->data.nb_flags & NB_GROUP)
108 #define NAME_BFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_BFLAG)
109 #define NAME_PFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_PFLAG)
110 #define NAME_MFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_MFLAG)
111 #define NAME_HFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_HFLAG)
113 /* Samba name state for a name in a namelist. */
114 #define NAME_IS_ACTIVE(p) ((p)->data.nb_flags & NB_ACTIVE)
115 #define NAME_IN_CONFLICT(p) ((p)->data.nb_flags & NB_CONFL)
116 #define NAME_IS_DEREGISTERING(p) ((p)->data.nb_flags & NB_DEREG)
118 /* Error codes for NetBIOS requests. */
119 #define FMT_ERR 0x1 /* Packet format error. */
120 #define SRV_ERR 0x2 /* Internal server error. */
121 #define NAM_ERR 0x3 /* Name does not exist. */
122 #define IMP_ERR 0x4 /* Request not implemented. */
123 #define RFS_ERR 0x5 /* Request refused. */
124 #define ACT_ERR 0x6 /* Active error - name owned by another host. */
125 #define CFT_ERR 0x7 /* Name in conflict error. */
127 #define REFRESH_TIME (15*60)
128 #define NAME_POLL_REFRESH_TIME (5*60)
129 #define NAME_POLL_INTERVAL 15
131 /* Microsoft browser NetBIOS name. */
132 #define MSBROWSE "\001\002__MSBROWSE__\002"
134 /* Mail slots. */
135 #define BROWSE_MAILSLOT "\\MAILSLOT\\BROWSE"
136 #define NET_LOGON_MAILSLOT "\\MAILSLOT\\NET\\NETLOGON"
137 #define NT_LOGON_MAILSLOT "\\MAILSLOT\\NET\\NTLOGON"
138 #define LANMAN_MAILSLOT "\\MAILSLOT\\LANMAN"
140 /* Samba definitions for find_name_on_subnet(). */
141 #define FIND_ANY_NAME 0
142 #define FIND_SELF_NAME 1
144 enum node_type {B_NODE=0, P_NODE=1, M_NODE=2, NBDD_NODE=3};
145 enum packet_type {NMB_PACKET, DGRAM_PACKET};
147 #define MAX_NETBIOSNAME_LEN 16
148 /* DOS character, NetBIOS namestring. Type used on the wire. */
149 typedef char nstring[MAX_NETBIOSNAME_LEN];
150 /* Unix character, NetBIOS namestring. Type used to manipulate name in nmbd. */
151 typedef char unstring[MAX_NETBIOSNAME_LEN*4];
153 /* A netbios name structure. */
154 struct nmb_name {
155 nstring name;
156 char scope[64];
157 unsigned int name_type;
160 /* A netbios node status array element. */
161 struct node_status {
162 nstring name;
163 unsigned char type;
164 unsigned char flags;
167 /* The extra info from a NetBIOS node status query */
168 struct node_status_extra {
169 unsigned char mac_addr[6];
170 /* There really is more here ... */
173 /* A resource record. */
174 struct res_rec {
175 struct nmb_name rr_name;
176 int rr_type;
177 int rr_class;
178 int ttl;
179 int rdlength;
180 char rdata[MAX_DGRAM_SIZE];
183 /* Define these so we can pass info back to caller of name_query */
184 #define NM_FLAGS_RS 0x80 /* Response. Cheat */
185 #define NM_FLAGS_AA 0x40 /* Authoritative */
186 #define NM_FLAGS_TC 0x20 /* Truncated */
187 #define NM_FLAGS_RD 0x10 /* Recursion Desired */
188 #define NM_FLAGS_RA 0x08 /* Recursion Available */
189 #define NM_FLAGS_B 0x01 /* Broadcast */
191 /* An nmb packet. */
192 struct nmb_packet {
193 struct {
194 int name_trn_id;
195 int opcode;
196 bool response;
197 struct {
198 bool bcast;
199 bool recursion_available;
200 bool recursion_desired;
201 bool trunc;
202 bool authoritative;
203 } nm_flags;
204 int rcode;
205 int qdcount;
206 int ancount;
207 int nscount;
208 int arcount;
209 } header;
211 struct {
212 struct nmb_name question_name;
213 int question_type;
214 int question_class;
215 } question;
217 struct res_rec *answers;
218 struct res_rec *nsrecs;
219 struct res_rec *additional;
222 /* msg_type field options - from rfc1002. */
224 #define DGRAM_UNIQUE 0x10
225 #define DGRAM_GROUP 0x11
226 #define DGRAM_BROADCAST 0x12
227 /* defined in IDL
228 #define DGRAM_ERROR 0x13
230 #define DGRAM_QUERY_REQUEST 0x14
231 #define DGRAM_POSITIVE_QUERY_RESPONSE 0x15
232 #define DGRAM_NEGATIVE_QUERT_RESPONSE 0x16
234 /* A datagram - this normally contains SMB data in the data[] array. */
236 struct dgram_packet {
237 struct {
238 int msg_type;
239 struct {
240 enum node_type node_type;
241 bool first;
242 bool more;
243 } flags;
244 int dgm_id;
245 struct in_addr source_ip;
246 int source_port;
247 int dgm_length;
248 int packet_offset;
249 } header;
250 struct nmb_name source_name;
251 struct nmb_name dest_name;
252 int datasize;
253 char data[MAX_DGRAM_SIZE];
256 /* Define a structure used to queue packets. This will be a linked
257 list of nmb packets. */
259 struct packet_struct
261 struct packet_struct *next;
262 struct packet_struct *prev;
263 bool locked;
264 struct in_addr ip;
265 int port;
266 int recv_fd;
267 int send_fd;
268 time_t timestamp;
269 enum packet_type packet_type;
270 union {
271 struct nmb_packet nmb;
272 struct dgram_packet dgram;
273 } packet;
276 /* Ids for netbios packet types. */
278 #define ANN_HostAnnouncement 1
279 #define ANN_AnnouncementRequest 2
280 #define ANN_Election 8
281 #define ANN_GetBackupListReq 9
282 #define ANN_GetBackupListResp 10
283 #define ANN_BecomeBackup 11
284 #define ANN_DomainAnnouncement 12
285 #define ANN_MasterAnnouncement 13
286 #define ANN_ResetBrowserState 14
287 #define ANN_LocalMasterAnnouncement 15
289 #endif /* _NAMESERV_H_ */