2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2005
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.
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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "lib/util/dlinklist.h"
25 #include "system/network.h"
26 #include "nbt_server/nbt_server.h"
27 #include "nbt_server/wins/winsserver.h"
28 #include "librpc/gen_ndr/ndr_nbt.h"
29 #include "lib/socket/socket.h"
34 void nbtd_request_query(struct nbt_name_socket *nbtsock,
35 struct nbt_name_packet *packet,
36 struct socket_address *src)
38 struct nbtd_iface_name *iname;
39 struct nbt_name *name;
40 struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private,
41 struct nbtd_interface);
43 /* see if its a node status query */
44 if (packet->qdcount == 1 &&
45 packet->questions[0].question_type == NBT_QTYPE_STATUS) {
46 nbtd_query_status(nbtsock, packet, src);
50 NBTD_ASSERT_PACKET(packet, src, packet->qdcount == 1);
51 NBTD_ASSERT_PACKET(packet, src,
52 packet->questions[0].question_type == NBT_QTYPE_NETBIOS);
53 NBTD_ASSERT_PACKET(packet, src,
54 packet->questions[0].question_class == NBT_QCLASS_IP);
56 /* see if we have the requested name on this interface */
57 name = &packet->questions[0].name;
59 iname = nbtd_find_iname(iface, name, 0);
61 /* don't send negative replies to broadcast queries */
62 if (packet->operation & NBT_FLAG_BROADCAST) {
66 if (packet->operation & NBT_FLAG_RECURSION_DESIRED) {
67 nbtd_winsserver_request(nbtsock, packet, src);
71 /* otherwise send a negative reply */
72 nbtd_negative_name_query_reply(nbtsock, packet, src);
77 * normally we should forward all queries with the
78 * recursion desired flag to the wins server, but this
79 * breaks are winsclient code, when doing mhomed registrations
81 if (!(packet->operation & NBT_FLAG_BROADCAST) &&
82 (packet->operation & NBT_FLAG_RECURSION_DESIRED) &&
83 (iname->nb_flags & NBT_NM_GROUP) &&
85 nbtd_winsserver_request(nbtsock, packet, src);
89 /* if the name is not yet active and its a broadcast query then
91 if (!(iname->nb_flags & NBT_NM_ACTIVE) &&
92 (packet->operation & NBT_FLAG_BROADCAST)) {
93 DEBUG(7,("Query for %s from %s - name not active yet on %s\n",
94 nbt_name_string(packet, name), src->addr, iface->ip_address));
98 nbtd_name_query_reply(nbtsock, packet, src,
99 &iname->name, iname->ttl, iname->nb_flags,
100 nbtd_address_list(iface, packet));