summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2005-10-14 12:22:15 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:39:52 -0500
commitfccbbf354634b31c9c3cb2bca15843f13e3b77f9 (patch)
tree6678adb19a88171fce5569d2183e212d08753aba /source4
parent0b0c38d899db75e6954af2618e7f063dbfc09fd6 (diff)
downloadsamba-fccbbf354634b31c9c3cb2bca15843f13e3b77f9.tar.gz
samba-fccbbf354634b31c9c3cb2bca15843f13e3b77f9.tar.bz2
samba-fccbbf354634b31c9c3cb2bca15843f13e3b77f9.zip
r10997: r11980@SERNOX (orig r10037): metze | 2005-09-05 14:21:40 +0200
add struct nbt_peer_socket and use it instead of passing const char *addr, uint16 port everyhwere (tridge: can you review this please, (make test works) metze (This used to be commit a599d7a4ae881c94be2c2d908a398838549942bb)
Diffstat (limited to 'source4')
-rw-r--r--source4/include/structs.h2
-rw-r--r--source4/libcli/dgram/browse.c9
-rw-r--r--source4/libcli/dgram/dgramsocket.c28
-rw-r--r--source4/libcli/dgram/libdgram.h22
-rw-r--r--source4/libcli/dgram/mailslot.c12
-rw-r--r--source4/libcli/dgram/netlogon.c10
-rw-r--r--source4/libcli/dgram/ntlogon.c10
-rw-r--r--source4/libcli/nbt/libnbt.h16
-rw-r--r--source4/libcli/nbt/namequery.c18
-rw-r--r--source4/libcli/nbt/namerefresh.c9
-rw-r--r--source4/libcli/nbt/nameregister.c9
-rw-r--r--source4/libcli/nbt/namerelease.c9
-rw-r--r--source4/libcli/nbt/nbtsocket.c39
-rw-r--r--source4/librpc/idl/nbt.idl2
-rw-r--r--source4/nbt_server/defense.c23
-rw-r--r--source4/nbt_server/interfaces.c14
-rw-r--r--source4/nbt_server/nodestatus.c18
-rw-r--r--source4/nbt_server/packet.c40
-rw-r--r--source4/nbt_server/query.c19
-rw-r--r--source4/nbt_server/wins/winsserver.c44
-rw-r--r--source4/nbt_server/wins/winswack.c25
-rw-r--r--source4/torture/nbt/dgram.c36
22 files changed, 218 insertions, 196 deletions
diff --git a/source4/include/structs.h b/source4/include/structs.h
index e67eca5c5c..bd0ebc5a27 100644
--- a/source4/include/structs.h
+++ b/source4/include/structs.h
@@ -246,6 +246,8 @@ struct nbt_name_refresh_wins;
struct nbt_name_register_wins;
struct nbt_name_request;
+struct nbt_peer_socket;
+
struct nbt_dgram_packet;
struct nbt_dgram_socket;
struct dgram_mailslot_handler;
diff --git a/source4/libcli/dgram/browse.c b/source4/libcli/dgram/browse.c
index a304db9c9d..d6813b36b9 100644
--- a/source4/libcli/dgram/browse.c
+++ b/source4/libcli/dgram/browse.c
@@ -29,7 +29,7 @@
#include "librpc/gen_ndr/ndr_nbt.h"
NTSTATUS dgram_mailslot_browse_send(struct nbt_dgram_socket *dgmsock,
- struct nbt_name *dest_name, const char *dest_address, int dest_port,
+ struct nbt_name *dest_name, const struct nbt_peer_socket *dest,
struct nbt_name *src_name, struct nbt_browse_packet *request)
{
NTSTATUS status;
@@ -45,7 +45,7 @@ NTSTATUS dgram_mailslot_browse_send(struct nbt_dgram_socket *dgmsock,
status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE,
NBT_MAILSLOT_BROWSE,
- dest_name, dest_address, dest_port,
+ dest_name, dest,
src_name, &blob);
talloc_free(tmp_ctx);
return status;
@@ -59,6 +59,7 @@ NTSTATUS dgram_mailslot_browse_reply(struct nbt_dgram_socket *dgmsock,
DATA_BLOB blob;
TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
struct nbt_name myname;
+ struct nbt_peer_socket dest;
status = ndr_push_struct_blob(&blob, tmp_ctx, reply,
(ndr_push_flags_fn_t)ndr_push_nbt_browse_packet);
@@ -69,10 +70,12 @@ NTSTATUS dgram_mailslot_browse_reply(struct nbt_dgram_socket *dgmsock,
make_nbt_name_client(&myname, lp_netbios_name());
+ dest.port = request->src_port;
+ dest.addr = request->src_addr;
status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE,
mailslot_name,
&request->data.msg.source_name,
- request->source, request->src_port,
+ &dest,
&myname, &blob);
talloc_free(tmp_ctx);
return status;
diff --git a/source4/libcli/dgram/dgramsocket.c b/source4/libcli/dgram/dgramsocket.c
index e66e5ed52e..decbc0225c 100644
--- a/source4/libcli/dgram/dgramsocket.c
+++ b/source4/libcli/dgram/dgramsocket.c
@@ -35,8 +35,7 @@ static void dgm_socket_recv(struct nbt_dgram_socket *dgmsock)
{
TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
NTSTATUS status;
- const char *src_addr;
- int src_port;
+ struct nbt_peer_socket src;
DATA_BLOB blob;
size_t nread, dsize;
struct nbt_dgram_packet *packet;
@@ -55,16 +54,16 @@ static void dgm_socket_recv(struct nbt_dgram_socket *dgmsock)
}
status = socket_recvfrom(dgmsock->sock, blob.data, blob.length, &nread, 0,
- &src_addr, &src_port);
+ &src.addr, &src.port);
if (!NT_STATUS_IS_OK(status)) {
talloc_free(tmp_ctx);
return;
}
- talloc_steal(tmp_ctx, src_addr);
+ talloc_steal(tmp_ctx, src.addr);
blob.length = nread;
DEBUG(2,("Received dgram packet of length %d from %s:%d\n",
- (int)blob.length, src_addr, src_port));
+ (int)blob.length, src.addr, src.port));
packet = talloc(tmp_ctx, struct nbt_dgram_packet);
if (packet == NULL) {
@@ -88,14 +87,14 @@ static void dgm_socket_recv(struct nbt_dgram_socket *dgmsock)
struct dgram_mailslot_handler *dgmslot;
dgmslot = dgram_mailslot_find(dgmsock, mailslot_name);
if (dgmslot) {
- dgmslot->handler(dgmslot, packet, src_addr, src_port);
+ dgmslot->handler(dgmslot, packet, &src);
} else {
DEBUG(2,("No mailslot handler for '%s'\n", mailslot_name));
}
} else {
/* dispatch if there is a general handler */
if (dgmsock->incoming.handler) {
- dgmsock->incoming.handler(dgmsock, packet, src_addr, src_port);
+ dgmsock->incoming.handler(dgmsock, packet, &src);
}
}
@@ -116,10 +115,10 @@ static void dgm_socket_send(struct nbt_dgram_socket *dgmsock)
len = req->encoded.length;
status = socket_sendto(dgmsock->sock, &req->encoded, &len, 0,
- req->dest_addr, req->dest_port);
+ req->dest.addr, req->dest.port);
if (NT_STATUS_IS_ERR(status)) {
DEBUG(3,("Failed to send datagram of length %u to %s:%d\n",
- (unsigned)req->encoded.length, req->dest_addr, req->dest_port));
+ (unsigned)req->encoded.length, req->dest.addr, req->dest.port));
DLIST_REMOVE(dgmsock->send_queue, req);
talloc_free(req);
continue;
@@ -201,7 +200,7 @@ failed:
NTSTATUS dgram_set_incoming_handler(struct nbt_dgram_socket *dgmsock,
void (*handler)(struct nbt_dgram_socket *,
struct nbt_dgram_packet *,
- const char *, int ),
+ const struct nbt_peer_socket *),
void *private)
{
dgmsock->incoming.handler = handler;
@@ -216,8 +215,7 @@ NTSTATUS dgram_set_incoming_handler(struct nbt_dgram_socket *dgmsock,
*/
NTSTATUS nbt_dgram_send(struct nbt_dgram_socket *dgmsock,
struct nbt_dgram_packet *packet,
- const char *dest_addr,
- int dest_port)
+ const struct nbt_peer_socket *dest)
{
struct nbt_dgram_request *req;
NTSTATUS status = NT_STATUS_NO_MEMORY;
@@ -225,9 +223,9 @@ NTSTATUS nbt_dgram_send(struct nbt_dgram_socket *dgmsock,
req = talloc(dgmsock, struct nbt_dgram_request);
if (req == NULL) goto failed;
- req->dest_addr = talloc_strdup(req, dest_addr);
- if (req->dest_addr == NULL) goto failed;
- req->dest_port = dest_port;
+ req->dest.port = dest->port;
+ req->dest.addr = talloc_strdup(req, dest->addr);
+ if (req->dest.addr == NULL) goto failed;
status = ndr_push_struct_blob(&req->encoded, req, packet,
(ndr_push_flags_fn_t)ndr_push_nbt_dgram_packet);
diff --git a/source4/libcli/dgram/libdgram.h b/source4/libcli/dgram/libdgram.h
index 5bddd220d0..f913e90d88 100644
--- a/source4/libcli/dgram/libdgram.h
+++ b/source4/libcli/dgram/libdgram.h
@@ -22,7 +22,6 @@
#include "librpc/gen_ndr/ndr_nbt.h"
-
/*
a datagram name request
*/
@@ -30,8 +29,7 @@ struct nbt_dgram_request {
struct nbt_dgram_request *next, *prev;
/* where to send the request */
- const char *dest_addr;
- int dest_port;
+ struct nbt_peer_socket dest;
/* the encoded request */
DATA_BLOB encoded;
@@ -56,7 +54,7 @@ struct nbt_dgram_socket {
/* what to do with incoming request packets */
struct {
void (*handler)(struct nbt_dgram_socket *, struct nbt_dgram_packet *,
- const char *, int );
+ const struct nbt_peer_socket *src);
void *private;
} incoming;
};
@@ -72,7 +70,7 @@ struct nbt_dgram_socket {
typedef void (*dgram_mailslot_handler_t)(struct dgram_mailslot_handler *,
struct nbt_dgram_packet *,
- const char *, int );
+ const struct nbt_peer_socket *src);
struct dgram_mailslot_handler {
struct dgram_mailslot_handler *next, *prev;
@@ -88,12 +86,11 @@ struct dgram_mailslot_handler {
/* prototypes */
NTSTATUS nbt_dgram_send(struct nbt_dgram_socket *dgmsock,
struct nbt_dgram_packet *packet,
- const char *dest_addr,
- int dest_port);
+ const struct nbt_peer_socket *dest);
NTSTATUS dgram_set_incoming_handler(struct nbt_dgram_socket *dgmsock,
void (*handler)(struct nbt_dgram_socket *,
struct nbt_dgram_packet *,
- const char *, int ),
+ const struct nbt_peer_socket *),
void *private);
struct nbt_dgram_socket *nbt_dgram_socket_init(TALLOC_CTX *mem_ctx,
struct event_context *event_ctx);
@@ -116,15 +113,13 @@ NTSTATUS dgram_mailslot_send(struct nbt_dgram_socket *dgmsock,
enum dgram_msg_type msg_type,
const char *mailslot_name,
struct nbt_name *dest_name,
- const char *dest_address,
- int dest_port,
+ const struct nbt_peer_socket *dest,
struct nbt_name *src_name,
DATA_BLOB *request);
NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock,
struct nbt_name *dest_name,
- const char *dest_address,
- int dest_port,
+ const struct nbt_peer_socket *dest,
struct nbt_name *src_name,
struct nbt_netlogon_packet *request);
NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock,
@@ -139,8 +134,7 @@ NTSTATUS dgram_mailslot_netlogon_parse(struct dgram_mailslot_handler *dgmslot,
NTSTATUS dgram_mailslot_ntlogon_send(struct nbt_dgram_socket *dgmsock,
enum dgram_msg_type msg_type,
struct nbt_name *dest_name,
- const char *dest_address,
- int dest_port,
+ const struct nbt_peer_socket *dest,
struct nbt_name *src_name,
struct nbt_ntlogon_packet *request);
NTSTATUS dgram_mailslot_ntlogon_reply(struct nbt_dgram_socket *dgmsock,
diff --git a/source4/libcli/dgram/mailslot.c b/source4/libcli/dgram/mailslot.c
index 14e7e49fc1..d521484422 100644
--- a/source4/libcli/dgram/mailslot.c
+++ b/source4/libcli/dgram/mailslot.c
@@ -152,27 +152,27 @@ NTSTATUS dgram_mailslot_send(struct nbt_dgram_socket *dgmsock,
enum dgram_msg_type msg_type,
const char *mailslot_name,
struct nbt_name *dest_name,
- const char *dest_address,
- int dest_port,
+ const struct nbt_peer_socket *_dest,
struct nbt_name *src_name,
DATA_BLOB *request)
{
TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
struct nbt_dgram_packet packet;
+ struct nbt_peer_socket dest = *_dest;
struct dgram_message *msg;
struct dgram_smb_packet *smb;
struct smb_trans_body *trans;
NTSTATUS status;
- if (dest_port == 0) {
- dest_port = lp_dgram_port();
+ if (dest.port == 0) {
+ dest.port = lp_dgram_port();
}
ZERO_STRUCT(packet);
packet.msg_type = msg_type;
packet.flags = DGRAM_FLAG_FIRST | DGRAM_NODE_NBDD;
packet.dgram_id = generate_random() % UINT16_MAX;
- packet.source = socket_get_my_addr(dgmsock->sock, tmp_ctx);
+ packet.src_addr = socket_get_my_addr(dgmsock->sock, tmp_ctx);
packet.src_port = socket_get_my_port(dgmsock->sock);
msg = &packet.data.msg;
@@ -199,7 +199,7 @@ NTSTATUS dgram_mailslot_send(struct nbt_dgram_socket *dgmsock,
trans->mailslot_name = mailslot_name;
trans->data = *request;
- status = nbt_dgram_send(dgmsock, &packet, dest_address, dest_port);
+ status = nbt_dgram_send(dgmsock, &packet, &dest);
talloc_free(tmp_ctx);
diff --git a/source4/libcli/dgram/netlogon.c b/source4/libcli/dgram/netlogon.c
index dda77689de..0627fe900c 100644
--- a/source4/libcli/dgram/netlogon.c
+++ b/source4/libcli/dgram/netlogon.c
@@ -33,8 +33,7 @@
*/
NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock,
struct nbt_name *dest_name,
- const char *dest_address,
- int dest_port,
+ const struct nbt_peer_socket *dest,
struct nbt_name *src_name,
struct nbt_netlogon_packet *request)
{
@@ -52,7 +51,7 @@ NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock,
status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE,
NBT_MAILSLOT_NETLOGON,
- dest_name, dest_address, dest_port,
+ dest_name, dest,
src_name, &blob);
talloc_free(tmp_ctx);
return status;
@@ -71,6 +70,7 @@ NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock,
DATA_BLOB blob;
TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
struct nbt_name myname;
+ struct nbt_peer_socket dest;
status = ndr_push_struct_blob(&blob, tmp_ctx, reply,
(ndr_push_flags_fn_t)ndr_push_nbt_netlogon_packet);
@@ -81,10 +81,12 @@ NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock,
make_nbt_name_client(&myname, lp_netbios_name());
+ dest.port = request->src_port;
+ dest.addr = request->src_addr;
status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE,
mailslot_name,
&request->data.msg.source_name,
- request->source, request->src_port,
+ &dest,
&myname, &blob);
talloc_free(tmp_ctx);
return status;
diff --git a/source4/libcli/dgram/ntlogon.c b/source4/libcli/dgram/ntlogon.c
index efa5d4ab9e..2bdce6f853 100644
--- a/source4/libcli/dgram/ntlogon.c
+++ b/source4/libcli/dgram/ntlogon.c
@@ -34,8 +34,7 @@
NTSTATUS dgram_mailslot_ntlogon_send(struct nbt_dgram_socket *dgmsock,
enum dgram_msg_type msg_type,
struct nbt_name *dest_name,
- const char *dest_address,
- int dest_port,
+ const struct nbt_peer_socket *dest,
struct nbt_name *src_name,
struct nbt_ntlogon_packet *request)
{
@@ -53,7 +52,7 @@ NTSTATUS dgram_mailslot_ntlogon_send(struct nbt_dgram_socket *dgmsock,
status = dgram_mailslot_send(dgmsock, msg_type,
NBT_MAILSLOT_NTLOGON,
- dest_name, dest_address, dest_port,
+ dest_name, dest,
src_name, &blob);
talloc_free(tmp_ctx);
return status;
@@ -72,6 +71,7 @@ NTSTATUS dgram_mailslot_ntlogon_reply(struct nbt_dgram_socket *dgmsock,
DATA_BLOB blob;
TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
struct nbt_name myname;
+ struct nbt_peer_socket dest;
status = ndr_push_struct_blob(&blob, tmp_ctx, reply,
(ndr_push_flags_fn_t)ndr_push_nbt_ntlogon_packet);
@@ -82,10 +82,12 @@ NTSTATUS dgram_mailslot_ntlogon_reply(struct nbt_dgram_socket *dgmsock,
make_nbt_name_client(&myname, lp_netbios_name());
+ dest.port = request->src_port;
+ dest.addr = request->src_addr;
status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE,
mailslot_name,
&request->data.msg.source_name,
- request->source, request->src_port,
+ &dest,
&myname, &blob);
talloc_free(tmp_ctx);
return status;
diff --git a/source4/libcli/nbt/libnbt.h b/source4/libcli/nbt/libnbt.h
index 5a53510ccf..218b5e5921 100644
--- a/source4/libcli/nbt/libnbt.h
+++ b/source4/libcli/nbt/libnbt.h
@@ -31,6 +31,12 @@ enum nbt_request_state {NBT_REQUEST_SEND,
NBT_REQUEST_TIMEOUT,
NBT_REQUEST_ERROR};
+/* where to send the request/replies */
+struct nbt_peer_socket {
+ const char *addr;
+ int port;
+};
+
/*
a nbt name request
*/
@@ -45,8 +51,7 @@ struct nbt_name_request {
struct nbt_name_socket *nbtsock;
/* where to send the request */
- const char *dest_addr;
- int dest_port;
+ struct nbt_peer_socket dest;
/* timeout between retries */
int timeout;
@@ -75,8 +80,7 @@ struct nbt_name_request {
uint_t num_replies;
struct nbt_name_reply {
struct nbt_name_packet *packet;
- const char *reply_addr;
- int reply_port;
+ struct nbt_peer_socket dest;
} *replies;
/* information on what to do on completion */
@@ -110,14 +114,14 @@ struct nbt_name_socket {
/* what to do with incoming request packets */
struct {
void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
- const char *, int );
+ const struct nbt_peer_socket *);
void *private;
} incoming;
/* what to do with unexpected replies */
struct {
void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
- const char *, int );
+ const struct nbt_peer_socket *);
void *private;
} unexpected;
};
diff --git a/source4/libcli/nbt/namequery.c b/source4/libcli/nbt/namequery.c
index f222148f4d..c0a1e274e2 100644
--- a/source4/libcli/nbt/namequery.c
+++ b/source4/libcli/nbt/namequery.c
@@ -31,6 +31,7 @@ struct nbt_name_request *nbt_name_query_send(struct nbt_name_socket *nbtsock,
{
struct nbt_name_request *req;
struct nbt_name_packet *packet;
+ struct nbt_peer_socket dest;
packet = talloc_zero(nbtsock, struct nbt_name_packet);
if (packet == NULL) return NULL;
@@ -50,8 +51,10 @@ struct nbt_name_request *nbt_name_query_send(struct nbt_name_socket *nbtsock,
packet->questions[0].name = io->in.name;
packet->questions[0].question_type = NBT_QTYPE_NETBIOS;
packet->questions[0].question_class = NBT_QCLASS_IP;
-
- req = nbt_name_request_send(nbtsock, io->in.dest_addr, lp_nbt_port(), packet,
+
+ dest.port = lp_nbt_port();
+ dest.addr = io->in.dest_addr;
+ req = nbt_name_request_send(nbtsock, &dest, packet,
io->in.timeout, io->in.retries, False);
if (req == NULL) goto failed;
@@ -81,7 +84,7 @@ NTSTATUS nbt_name_query_recv(struct nbt_name_request *req,
}
packet = req->replies[0].packet;
- io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].reply_addr);
+ io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest.addr);
if ((packet->operation & NBT_RCODE) != 0) {
status = nbt_rcode_to_ntstatus(packet->operation & NBT_RCODE);
@@ -137,6 +140,7 @@ struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *nbtsock,
{
struct nbt_name_request *req;
struct nbt_name_packet *packet;
+ struct nbt_peer_socket dest;
packet = talloc_zero(nbtsock, struct nbt_name_packet);
if (packet == NULL) return NULL;
@@ -150,8 +154,10 @@ struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *nbtsock,
packet->questions[0].name = io->in.name;
packet->questions[0].question_type = NBT_QTYPE_STATUS;
packet->questions[0].question_class = NBT_QCLASS_IP;
-
- req = nbt_name_request_send(nbtsock, io->in.dest_addr, lp_nbt_port(), packet,
+
+ dest.port = lp_nbt_port();
+ dest.addr = io->in.dest_addr;
+ req = nbt_name_request_send(nbtsock, &dest, packet,
io->in.timeout, io->in.retries, False);
if (req == NULL) goto failed;
@@ -181,7 +187,7 @@ NTSTATUS nbt_name_status_recv(struct nbt_name_request *req,
}
packet = req->replies[0].packet;
- io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].reply_addr);
+ io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest.addr);
if ((packet->operation & NBT_RCODE) != 0) {
status = nbt_rcode_to_ntstatus(packet->operation & NBT_RCODE);
diff --git a/source4/libcli/nbt/namerefresh.c b/source4/libcli/nbt/namerefresh.c
index d9f2070d4c..e6464885f7 100644
--- a/source4/libcli/nbt/namerefresh.c
+++ b/source4/libcli/nbt/namerefresh.c
@@ -32,6 +32,7 @@ struct nbt_name_request *nbt_name_refresh_send(struct nbt_name_socket *nbtsock,
{
struct nbt_name_request *req;
struct nbt_name_packet *packet;
+ struct nbt_peer_socket dest;
packet = talloc_zero(nbtsock, struct nbt_name_packet);
if (packet == NULL) return NULL;
@@ -64,8 +65,10 @@ struct nbt_name_request *nbt_name_refresh_send(struct nbt_name_socket *nbtsock,
packet->additional[0].rdata.netbios.addresses[0].nb_flags = io->in.nb_flags;
packet->additional[0].rdata.netbios.addresses[0].ipaddr =
talloc_strdup(packet->additional, io->in.address);
-
- req = nbt_name_request_send(nbtsock, io->in.dest_addr, lp_nbt_port(), packet,
+
+ dest.port = lp_nbt_port();
+ dest.addr = io->in.dest_addr;
+ req = nbt_name_request_send(nbtsock, &dest, packet,
io->in.timeout, io->in.retries, False);
if (req == NULL) goto failed;
@@ -94,7 +97,7 @@ NTSTATUS nbt_name_refresh_recv(struct nbt_name_request *req,
}
packet = req->replies[0].packet;
- io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].reply_addr);
+ io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest.addr);
if (packet->ancount != 1 ||
packet->answers[0].rr_type != NBT_QTYPE_NETBIOS ||
diff --git a/source4/libcli/nbt/nameregister.c b/source4/libcli/nbt/nameregister.c
index 4dac500780..4f3e046274 100644
--- a/source4/libcli/nbt/nameregister.c
+++ b/source4/libcli/nbt/nameregister.c
@@ -32,6 +32,7 @@ struct nbt_name_request *nbt_name_register_send(struct nbt_name_socket *nbtsock,
{
struct nbt_name_request *req;
struct nbt_name_packet *packet;
+ struct nbt_peer_socket dest;
packet = talloc_zero(nbtsock, struct nbt_name_packet);
if (packet == NULL) return NULL;
@@ -72,8 +73,10 @@ struct nbt_name_request *nbt_name_register_send(struct nbt_name_socket *nbtsock,
packet->additional[0].rdata.netbios.addresses[0].ipaddr =
talloc_strdup(packet->additional, io->in.address);
if (packet->additional[0].rdata.netbios.addresses[0].ipaddr == NULL) goto failed;
-
- req = nbt_name_request_send(nbtsock, io->in.dest_addr, lp_nbt_port(), packet,
+
+ dest.port = lp_nbt_port();
+ dest.addr = io->in.dest_addr;
+ req = nbt_name_request_send(nbtsock, &dest, packet,
io->in.timeout, io->in.retries, False);
if (req == NULL) goto failed;
@@ -102,7 +105,7 @@ NTSTATUS nbt_name_register_recv(struct nbt_name_request *req,
}
packet = req->replies[0].packet;
- io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].reply_addr);
+ io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest.addr);
if (packet->ancount != 1 ||
packet->answers[0].rr_type != NBT_QTYPE_NETBIOS ||
diff --git a/source4/libcli/nbt/namerelease.c b/source4/libcli/nbt/namerelease.c
index 208c73d386..0a0cd45276 100644
--- a/source4/libcli/nbt/namerelease.c
+++ b/source4/libcli/nbt/namerelease.c
@@ -31,6 +31,7 @@ struct nbt_name_request *nbt_name_release_send(struct nbt_name_socket *nbtsock,
{
struct nbt_name_request *req;
struct nbt_name_packet *packet;
+ struct nbt_peer_socket dest;
packet = talloc_zero(nbtsock, struct nbt_name_packet);
if (packet == NULL) return NULL;
@@ -63,8 +64,10 @@ struct nbt_name_request *nbt_name_release_send(struct nbt_name_socket *nbtsock,
packet->additional[0].rdata.netbios.addresses[0].nb_flags = io->in.nb_flags;
packet->additional[0].rdata.netbios.addresses[0].ipaddr =
talloc_strdup(packet->additional, io->in.address);
-
- req = nbt_name_request_send(nbtsock, io->in.dest_addr, lp_nbt_port(), packet,
+
+ dest.port = lp_nbt_port();
+ dest.addr = io->in.dest_addr;
+ req = nbt_name_request_send(nbtsock, &dest, packet,
io->in.timeout, io->in.retries, False);
if (req == NULL) goto failed;
@@ -93,7 +96,7 @@ NTSTATUS nbt_name_release_recv(struct nbt_name_request *req,
}
packet = req->replies[0].packet;
- io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].reply_addr);
+ io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest.addr);
if (packet->ancount != 1 ||
packet->answers[0].rr_type != NBT_QTYPE_NETBIOS ||
diff --git a/source4/libcli/nbt/nbtsocket.c b/source4/libcli/nbt/nbtsocket.c
index f40ec84e77..905541e74a 100644
--- a/source4/libcli/nbt/nbtsocket.c
+++ b/source4/libcli/nbt/nbtsocket.c
@@ -73,7 +73,7 @@ static void nbt_name_socket_send(struct nbt_name_socket *nbtsock)
len = req->encoded.length;
status = socket_sendto(nbtsock->sock, &req->encoded, &len, 0,
- req->dest_addr, req->dest_port);
+ req->dest.addr, req->dest.port);
if (NT_STATUS_IS_ERR(status)) goto failed;
if (!NT_STATUS_IS_OK(status)) {
@@ -153,8 +153,7 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
{
TALLOC_CTX *tmp_ctx = talloc_new(nbtsock);
NTSTATUS status;
- const char *src_addr;
- int src_port;
+ struct nbt_peer_socket src;
DATA_BLOB blob;
size_t nread, dsize;
struct nbt_name_packet *packet;
@@ -173,12 +172,12 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
}
status = socket_recvfrom(nbtsock->sock, blob.data, blob.length, &nread, 0,
- &src_addr, &src_port);
+ &src.addr, &src.port);
if (!NT_STATUS_IS_OK(status)) {
talloc_free(tmp_ctx);
return;
}
- talloc_steal(tmp_ctx, src_addr);
+ talloc_steal(tmp_ctx, src.addr);
blob.length = nread;
packet = talloc(tmp_ctx, struct nbt_name_packet);
@@ -199,7 +198,7 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
if (DEBUGLVL(10)) {
DEBUG(10,("Received nbt packet of length %d from %s:%d\n",
- (int)blob.length, src_addr, src_port));
+ (int)blob.length, src.addr, src.port));
NDR_PRINT_DEBUG(nbt_name_packet, packet);
}
@@ -207,7 +206,7 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
handler, if any */
if (!(packet->operation & NBT_FLAG_REPLY)) {
if (nbtsock->incoming.handler) {
- nbtsock->incoming.handler(nbtsock, packet, src_addr, src_port);
+ nbtsock->incoming.handler(nbtsock, packet, &src);
}
talloc_free(tmp_ctx);
return;
@@ -217,7 +216,7 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
req = idr_find(nbtsock->idr, packet->name_trn_id);
if (req == NULL) {
if (nbtsock->unexpected.handler) {
- nbtsock->unexpected.handler(nbtsock, packet, src_addr, src_port);
+ nbtsock->unexpected.handler(nbtsock, packet, &src);
} else {
DEBUG(2,("Failed to match request for incoming name packet id 0x%04x on %p\n",
packet->name_trn_id, nbtsock));
@@ -259,8 +258,8 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
goto done;
}
- req->replies[req->num_replies].reply_addr = talloc_steal(req, src_addr);
- req->replies[req->num_replies].reply_port = src_port;
+ req->replies[req->num_replies].dest.addr = talloc_steal(req, src.addr);
+ req->replies[req->num_replies].dest.port = src.port;
req->replies[req->num_replies].packet = talloc_steal(req, packet);
req->num_replies++;
@@ -349,7 +348,7 @@ failed:
send off a nbt name request
*/
struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock,
- const char *dest_addr, int dest_port,
+ const struct nbt_peer_socket *dest,
struct nbt_name_packet *request,
int timeout, int retries,
BOOL allow_multiple_replies)
@@ -362,14 +361,14 @@ struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock,
if (req == NULL) goto failed;
req->nbtsock = nbtsock;
- req->dest_port = dest_port;
req->allow_multiple_replies = allow_multiple_replies;
req->state = NBT_REQUEST_SEND;
req->is_reply = False;
req->timeout = timeout;
req->num_retries = retries;
- req->dest_addr = talloc_strdup(req, dest_addr);
- if (req->dest_addr == NULL) goto failed;
+ req->dest.port = dest->port;
+ req->dest.addr = talloc_strdup(req, dest->addr);
+ if (req->dest.addr == NULL) goto failed;
/* we select a random transaction id unless the user supplied one */
if (request->name_trn_id == 0) {
@@ -398,7 +397,7 @@ struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock,
if (DEBUGLVL(10)) {
DEBUG(10,("Queueing nbt packet to %s:%d\n",
- req->dest_addr, req->dest_port));
+ req->dest.addr, req->dest.port));
NDR_PRINT_DEBUG(nbt_name_packet, request);
}
@@ -416,7 +415,7 @@ failed:
send off a nbt name reply
*/
NTSTATUS nbt_name_reply_send(struct nbt_name_socket *nbtsock,
- const char *dest_addr, int dest_port,
+ const struct nbt_peer_socket *dest,
struct nbt_name_packet *request)
{
struct nbt_name_request *req;
@@ -426,9 +425,9 @@ NTSTATUS nbt_name_reply_send(struct nbt_name_socket *nbtsock,
NT_STATUS_HAVE_NO_MEMORY(req);
req->nbtsock = nbtsock;
- req->dest_addr = talloc_strdup(req, dest_addr);
- if (req->dest_addr == NULL) goto failed;
- req->dest_port = dest_port;
+ req->dest.port = dest->port;
+ req->dest.addr = talloc_strdup(req, dest->addr);
+ if (req->dest.addr == NULL) goto failed;
req->state = NBT_REQUEST_SEND;
req->is_reply = True;
@@ -481,7 +480,7 @@ NTSTATUS nbt_name_request_recv(struct nbt_name_request *req)
*/
NTSTATUS nbt_set_incoming_handler(struct nbt_name_socket *nbtsock,
void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
- const char *, int ),
+ const struct nbt_peer_socket *),
void *private)
{
nbtsock->incoming.handler = handler;
diff --git a/source4/librpc/idl/nbt.idl b/source4/librpc/idl/nbt.idl
index e3c72480fc..e188c61d86 100644
--- a/source4/librpc/idl/nbt.idl
+++ b/source4/librpc/idl/nbt.idl
@@ -319,7 +319,7 @@
dgram_msg_type msg_type;
dgram_flags flags;
uint16 dgram_id;
- ipv4address source;
+ ipv4address src_addr;
uint16 src_port;
[switch_is(msg_type)] dgram_data data;
} nbt_dgram_packet;
diff --git a/source4/nbt_server/defense.c b/source4/nbt_server/defense.c
index 8d71b31c65..f8c73c6a3a 100644
--- a/source4/nbt_server/defense.c
+++ b/source4/nbt_server/defense.c
@@ -32,24 +32,24 @@
*/
void nbtd_request_defense(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *packet,
- const char *src_address, int src_port)
+ const struct nbt_peer_socket *src)
{
struct nbtd_iface_name *iname;
struct nbt_name *name;
struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private,
struct nbtd_interface);
- NBTD_ASSERT_PACKET(packet, src_address, packet->qdcount == 1);
- NBTD_ASSERT_PACKET(packet, src_address, packet->arcount == 1);
- NBTD_ASSERT_PACKET(packet, src_address,
+ NBTD_ASSERT_PACKET(packet, src->addr, packet->qdcount == 1);
+ NBTD_ASSERT_PACKET(packet, src->addr, packet->arcount == 1);
+ NBTD_ASSERT_PACKET(packet, src->addr,
packet->questions[0].question_type == NBT_QTYPE_NETBIOS);
- NBTD_ASSERT_PACKET(packet, src_address,
+ NBTD_ASSERT_PACKET(packet, src->addr,
packet->questions[0].question_class == NBT_QCLASS_IP);
- NBTD_ASSERT_PACKET(packet, src_address,
+ NBTD_ASSERT_PACKET(packet, src->addr,
packet->additional[0].rr_type == NBT_QTYPE_NETBIOS);
- NBTD_ASSERT_PACKET(packet, src_address,
+ NBTD_ASSERT_PACKET(packet, src->addr,
packet->additional[0].rr_class == NBT_QCLASS_IP);
- NBTD_ASSERT_PACKET(packet, src_address,
+ NBTD_ASSERT_PACKET(packet, src->addr,
packet->additional[0].rdata.netbios.length == 6);
/* see if we have the requested name on this interface */
@@ -60,10 +60,9 @@ void nbtd_request_defense(struct nbt_name_socket *nbtsock,
!IS_GROUP_NAME(name, iname->nb_flags)) {
DEBUG(2,("Defending name %s on %s against %s\n",
nbt_name_string(packet, name),
- iface->bcast_address, src_address));
- nbtd_name_registration_reply(nbtsock, packet,
- src_address, src_port, NBT_RCODE_ACT);
+ iface->bcast_address, src->addr));
+ nbtd_name_registration_reply(nbtsock, packet, src, NBT_RCODE_ACT);
} else {
- nbtd_winsserver_request(nbtsock, packet, src_address, src_port);
+ nbtd_winsserver_request(nbtsock, packet, src);
}
}
diff --git a/source4/nbt_server/interfaces.c b/source4/nbt_server/interfaces.c
index aa22e5d4ad..23276123d5 100644
--- a/source4/nbt_server/interfaces.c
+++ b/source4/nbt_server/interfaces.c
@@ -32,7 +32,7 @@
*/
static void nbtd_request_handler(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *packet,
- const char *src_address, int src_port)
+ const struct nbt_peer_socket *src)
{
struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private,
struct nbtd_interface);
@@ -41,32 +41,32 @@ static void nbtd_request_handler(struct nbt_name_socket *nbtsock,
nbtsrv->stats.total_received++;
/* see if its from one of our own interfaces - if so, then ignore it */
- if (nbtd_self_packet(nbtsock, packet, src_address, src_port)) {
- DEBUG(10,("Ignoring self packet from %s:%d\n", src_address, src_port));
+ if (nbtd_self_packet(nbtsock, packet, src)) {
+ DEBUG(10,("Ignoring self packet from %s:%d\n", src->addr, src->port));
return;
}
switch (packet->operation & NBT_OPCODE) {
case NBT_OPCODE_QUERY:
nbtsrv->stats.query_count++;
- nbtd_request_query(nbtsock, packet, src_address, src_port);
+ nbtd_request_query(nbtsock, packet, src);
break;
case NBT_OPCODE_REGISTER:
case NBT_OPCODE_REFRESH:
case NBT_OPCODE_REFRESH2:
nbtsrv->stats.register_count++;
- nbtd_request_defense(nbtsock, packet, src_address, src_port);
+ nbtd_request_defense(nbtsock, packet, src);
break;
case NBT_OPCODE_RELEASE:
case NBT_OPCODE_MULTI_HOME_REG:
nbtsrv->stats.release_count++;
- nbtd_winsserver_request(nbtsock, packet, src_address, src_port);
+ nbtd_winsserver_request(nbtsock, packet, src);
break;
default:
- nbtd_bad_packet(packet, src_address, "Unexpected opcode");
+ nbtd_bad_packet(packet, src, "Unexpected opcode");
break;
}
}
diff --git a/source4/nbt_server/nodestatus.c b/source4/nbt_server/nodestatus.c
index daae7b8a78..ccbdc2b933 100644
--- a/source4/nbt_server/nodestatus.c
+++ b/source4/nbt_server/nodestatus.c
@@ -30,7 +30,7 @@
*/
static void nbtd_node_status_reply(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *request_packet,
- const char *src_address, int src_port,
+ const struct nbt_peer_socket *src,
struct nbt_name *name,
struct nbtd_interface *iface)
{
@@ -84,10 +84,10 @@ static void nbtd_node_status_reply(struct nbt_name_socket *nbtsock,
ZERO_STRUCT(packet->answers[0].rdata.status.statistics);
DEBUG(7,("Sending node status reply for %s to %s:%d\n",
- nbt_name_string(packet, name), src_address, src_port));
+ nbt_name_string(packet, name), src->addr, src->port));
nbtsrv->stats.total_sent++;
- nbt_name_reply_send(nbtsock, src_address, src_port, packet);
+ nbt_name_reply_send(nbtsock, src, packet);
failed:
talloc_free(packet);
@@ -99,16 +99,16 @@ failed:
*/
void nbtd_query_status(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *packet,
- const char *src_address, int src_port)
+ const struct nbt_peer_socket *src)
{
struct nbt_name *name;
struct nbtd_iface_name *iname;
struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private,
struct nbtd_interface);
- NBTD_ASSERT_PACKET(packet, src_address, packet->qdcount == 1);
- NBTD_ASSERT_PACKET(packet, src_address, packet->questions[0].question_type == NBT_QTYPE_STATUS);
- NBTD_ASSERT_PACKET(packet, src_address, packet->questions[0].question_class == NBT_QCLASS_IP);
+ NBTD_ASSERT_PACKET(packet, src->addr, packet->qdcount == 1);
+ NBTD_ASSERT_PACKET(packet, src->addr, packet->questions[0].question_type == NBT_QTYPE_STATUS);
+ NBTD_ASSERT_PACKET(packet, src->addr, packet->questions[0].question_class == NBT_QCLASS_IP);
/* see if we have the requested name on this interface */
name = &packet->questions[0].name;
@@ -116,10 +116,10 @@ void nbtd_query_status(struct nbt_name_socket *nbtsock,
iname = nbtd_find_iname(iface, name, NBT_NM_ACTIVE);
if (iname == NULL) {
DEBUG(7,("Node status query for %s from %s - not found on %s\n",
- nbt_name_string(packet, name), src_address, iface->ip_address));
+ nbt_name_string(packet, name), src->addr, iface->ip_address));
return;
}
- nbtd_node_status_reply(nbtsock, packet, src_address, src_port,
+ nbtd_node_status_reply(nbtsock, packet, src,
&iname->name, iface);
}
diff --git a/source4/nbt_server/packet.c b/source4/nbt_server/packet.c
index c1e0c4411b..9c9983b63c 100644
--- a/source4/nbt_server/packet.c
+++ b/source4/nbt_server/packet.c
@@ -28,9 +28,9 @@
we received a badly formed packet - log it
*/
void nbtd_bad_packet(struct nbt_name_packet *packet,
- const char *src_address, const char *reason)
+ const struct nbt_peer_socket *src, const char *reason)
{
- DEBUG(2,("nbtd: bad packet '%s' from %s\n", reason, src_address));
+ DEBUG(2,("nbtd: bad packet '%s' from %s:%d\n", reason, src->addr, src->port));
if (DEBUGLVL(5)) {
NDR_PRINT_DEBUG(nbt_name_packet, packet);
}
@@ -43,7 +43,7 @@ void nbtd_bad_packet(struct nbt_name_packet *packet,
*/
BOOL nbtd_self_packet(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *packet,
- const char *src_address, int src_port)
+ const struct nbt_peer_socket *src)
{
struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private,
struct nbtd_interface);
@@ -55,7 +55,7 @@ BOOL nbtd_self_packet(struct nbt_name_socket *nbtsock,
}
/* if its not from the nbt port, then it wasn't a broadcast from us */
- if (src_port != lp_nbt_port()) {
+ if (src->port != lp_nbt_port()) {
return False;
}
@@ -69,7 +69,7 @@ BOOL nbtd_self_packet(struct nbt_name_socket *nbtsock,
/* we have to loop over our interface list, seeing if its from
one of our own interfaces */
for (iface=nbtsrv->interfaces;iface;iface=iface->next) {
- if (strcmp(src_address, iface->ip_address) == 0) {
+ if (strcmp(src->addr, iface->ip_address) == 0) {
return True;
}
}
@@ -83,7 +83,7 @@ BOOL nbtd_self_packet(struct nbt_name_socket *nbtsock,
*/
void nbtd_name_query_reply(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *request_packet,
- const char *src_address, int src_port,
+ const struct nbt_peer_socket *src,
struct nbt_name *name, uint32_t ttl,
uint16_t nb_flags, const char **addresses)
{
@@ -132,10 +132,10 @@ void nbtd_name_query_reply(struct nbt_name_socket *nbtsock,
}
DEBUG(7,("Sending name query reply for %s at %s to %s:%d\n",
- nbt_name_string(packet, name), addresses[0], src_address, src_port));
+ nbt_name_string(packet, name), addresses[0], src->addr, src->port));
nbtsrv->stats.total_sent++;
- nbt_name_reply_send(nbtsock, src_address, src_port, packet);
+ nbt_name_reply_send(nbtsock, src, packet);
failed:
talloc_free(packet);
@@ -147,7 +147,7 @@ failed:
*/
void nbtd_negative_name_query_reply(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *request_packet,
- const char *src_address, int src_port)
+ const struct nbt_peer_socket *src)
{
struct nbt_name_packet *packet;
struct nbt_name *name = &request_packet->questions[0].name;
@@ -176,10 +176,10 @@ void nbtd_negative_name_query_reply(struct nbt_name_socket *nbtsock,
ZERO_STRUCT(packet->answers[0].rdata);
DEBUG(7,("Sending negative name query reply for %s to %s:%d\n",
- nbt_name_string(packet, name), src_address, src_port));
+ nbt_name_string(packet, name), src->addr, src->port));
nbtsrv->stats.total_sent++;
- nbt_name_reply_send(nbtsock, src_address, src_port, packet);
+ nbt_name_reply_send(nbtsock, src, packet);
failed:
talloc_free(packet);
@@ -190,7 +190,7 @@ failed:
*/
void nbtd_name_registration_reply(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *request_packet,
- const char *src_address, int src_port,
+ const struct nbt_peer_socket *src,
uint8_t rcode)
{
struct nbt_name_packet *packet;
@@ -223,10 +223,10 @@ void nbtd_name_registration_reply(struct nbt_name_socket *nbtsock,
DEBUG(7,("Sending %s name registration reply for %s to %s:%d\n",
rcode==0?"positive":"negative",
- nbt_name_string(packet, name), src_address, src_port));
+ nbt_name_string(packet, name), src->addr, src->port));
nbtsrv->stats.total_sent++;
- nbt_name_reply_send(nbtsock, src_address, src_port, packet);
+ nbt_name_reply_send(nbtsock, src, packet);
failed:
talloc_free(packet);
@@ -238,7 +238,7 @@ failed:
*/
void nbtd_name_release_reply(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *request_packet,
- const char *src_address, int src_port,
+ const struct nbt_peer_socket *src,
uint8_t rcode)
{
struct nbt_name_packet *packet;
@@ -269,10 +269,10 @@ void nbtd_name_release_reply(struct nbt_name_socket *nbtsock,
DEBUG(7,("Sending %s name release reply for %s to %s:%d\n",
rcode==0?"positive":"negative",
- nbt_name_string(packet, name), src_address, src_port));
+ nbt_name_string(packet, name), src->addr, src->port));
nbtsrv->stats.total_sent++;
- nbt_name_reply_send(nbtsock, src_address, src_port, packet);
+ nbt_name_reply_send(nbtsock, src, packet);
failed:
talloc_free(packet);
@@ -284,7 +284,7 @@ failed:
*/
void nbtd_wack_reply(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *request_packet,
- const char *src_address, int src_port,
+ const struct nbt_peer_socket *src,
uint32_t ttl)
{
struct nbt_name_packet *packet;
@@ -316,10 +316,10 @@ void nbtd_wack_reply(struct nbt_name_socket *nbtsock,
RSSVAL(packet->answers[0].rdata.data.data, 0, request_packet->operation);
DEBUG(7,("Sending WACK reply for %s to %s:%d\n",
- nbt_name_string(packet, name), src_address, src_port));
+ nbt_name_string(packet, name), src->addr, src->port));
nbtsrv->stats.total_sent++;
- nbt_name_reply_send(nbtsock, src_address, src_port, packet);
+ nbt_name_reply_send(nbtsock, src, packet);
failed:
talloc_free(packet);
diff --git a/source4/nbt_server/query.c b/source4/nbt_server/query.c
index c51a146adf..c64ac5986a 100644
--- a/source4/nbt_server/query.c
+++ b/source4/nbt_server/query.c
@@ -31,7 +31,7 @@
*/
void nbtd_request_query(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *packet,
- const char *src_address, int src_port)
+ const struct nbt_peer_socket *src)
{
struct nbtd_iface_name *iname;
struct nbt_name *name;
@@ -41,14 +41,14 @@ void nbtd_request_query(struct nbt_name_socket *nbtsock,
/* see if its a node status query */
if (packet->qdcount == 1 &&
packet->questions[0].question_type == NBT_QTYPE_STATUS) {
- nbtd_query_status(nbtsock, packet, src_address, src_port);
+ nbtd_query_status(nbtsock, packet, src);
return;
}
- NBTD_ASSERT_PACKET(packet, src_address, packet->qdcount == 1);
- NBTD_ASSERT_PACKET(packet, src_address,
+ NBTD_ASSERT_PACKET(packet, src->addr, packet->qdcount == 1);
+ NBTD_ASSERT_PACKET(packet, src->addr,
packet->questions[0].question_type == NBT_QTYPE_NETBIOS);
- NBTD_ASSERT_PACKET(packet, src_address,
+ NBTD_ASSERT_PACKET(packet, src->addr,
packet->questions[0].question_class == NBT_QCLASS_IP);
/* see if we have the requested name on this interface */
@@ -65,13 +65,12 @@ void nbtd_request_query(struct nbt_name_socket *nbtsock,
/* if the name does not exist, then redirect to WINS
server if recursion has been asked for */
if (packet->operation & NBT_FLAG_RECURSION_DESIRED) {
- nbtd_winsserver_request(nbtsock, packet, src_address, src_port);
+ nbtd_winsserver_request(nbtsock, packet, src);
return;
}
/* otherwise send a negative reply */
- nbtd_negative_name_query_reply(nbtsock, packet,
- src_address, src_port);
+ nbtd_negative_name_query_reply(nbtsock, packet, src);
return;
}
@@ -80,11 +79,11 @@ void nbtd_request_query(struct nbt_name_socket *nbtsock,
if (!(iname->nb_flags & NBT_NM_ACTIVE) &&
(packet->operation & NBT_FLAG_BROADCAST)) {
DEBUG(7,("Query for %s from %s - name not active yet on %s\n",
- nbt_name_string(packet, name), src_address, iface->ip_address));
+ nbt_name_string(packet, name), src->addr, iface->ip_address));
return;
}
- nbtd_name_query_reply(nbtsock, packet, src_address, src_port,
+ nbtd_name_query_reply(nbtsock, packet, src,
&iname->name, iname->ttl, iname->nb_flags,
nbtd_address_list(iface, packet));
}
diff --git a/source4/nbt_server/wins/winsserver.c b/source4/nbt_server/wins/winsserver.c
index 5470a38c97..c9758b3162 100644
--- a/source4/nbt_server/wins/winsserver.c
+++ b/source4/nbt_server/wins/winsserver.c
@@ -41,7 +41,7 @@ uint32_t wins_server_ttl(struct wins_server *winssrv, uint32_t ttl)
*/
static uint8_t wins_register_new(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *packet,
- const char *src_address, int src_port)
+ const struct nbt_peer_socket *src)
{
struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private,
struct nbtd_interface);
@@ -56,7 +56,7 @@ static uint8_t wins_register_new(struct nbt_name_socket *nbtsock,
rec.nb_flags = nb_flags;
rec.state = WINS_REC_ACTIVE;
rec.expire_time = time(NULL) + ttl;
- rec.registered_by = src_address;
+ rec.registered_by = src->addr;
if (IS_GROUP_NAME(name, nb_flags)) {
rec.addresses = str_list_make(packet, "255.255.255.255", NULL);
} else {
@@ -77,7 +77,7 @@ static uint8_t wins_register_new(struct nbt_name_socket *nbtsock,
static uint8_t wins_update_ttl(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *packet,
struct winsdb_record *rec,
- const char *src_address, int src_port)
+ const struct nbt_peer_socket *src)
{
struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private,
struct nbtd_interface);
@@ -89,7 +89,7 @@ static uint8_t wins_update_ttl(struct nbt_name_socket *nbtsock,
if (now + ttl > rec->expire_time) {
rec->expire_time = now + ttl;
}
- rec->registered_by = src_address;
+ rec->registered_by = src->addr;
DEBUG(5,("WINS: refreshed registration of %s at %s\n",
nbt_name_string(packet, rec->name), address));
@@ -102,7 +102,7 @@ static uint8_t wins_update_ttl(struct nbt_name_socket *nbtsock,
*/
static void nbtd_winsserver_register(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *packet,
- const char *src_address, int src_port)
+ const struct nbt_peer_socket *src)
{
struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private,
struct nbtd_interface);
@@ -121,11 +121,11 @@ static void nbtd_winsserver_register(struct nbt_name_socket *nbtsock,
rec = winsdb_load(winssrv, name, packet);
if (rec == NULL) {
- rcode = wins_register_new(nbtsock, packet, src_address, src_port);
+ rcode = wins_register_new(nbtsock, packet, src);
goto done;
} else if (rec->state != WINS_REC_ACTIVE) {
winsdb_delete(winssrv, rec);
- rcode = wins_register_new(nbtsock, packet, src_address, src_port);
+ rcode = wins_register_new(nbtsock, packet, src);
goto done;
}
@@ -140,31 +140,31 @@ static void nbtd_winsserver_register(struct nbt_name_socket *nbtsock,
/* if its an active unique name, and the registration is for a group, then
see if the unique name owner still wants the name */
if (!(rec->nb_flags & NBT_NM_GROUP) && (nb_flags & NBT_NM_GROUP)) {
- wins_register_wack(nbtsock, packet, rec, src_address, src_port);
+ wins_register_wack(nbtsock, packet, rec, src);
return;
}
/* if the registration is for a group, then just update the expiry time
and we are done */
if (IS_GROUP_NAME(name, nb_flags)) {
- wins_update_ttl(nbtsock, packet, rec, src_address, src_port);
+ wins_update_ttl(nbtsock, packet, rec, src);
goto done;
}
/* if the registration is for an address that is currently active, then
just update the expiry time */
if (str_list_check(rec->addresses, address)) {
- wins_update_ttl(nbtsock, packet, rec, src_address, src_port);
+ wins_update_ttl(nbtsock, packet, rec, src);
goto done;
}
/* we have to do a WACK to see if the current owner is willing
to give up its claim */
- wins_register_wack(nbtsock, packet, rec, src_address, src_port);
+ wins_register_wack(nbtsock, packet, rec, src);
return;
done:
- nbtd_name_registration_reply(nbtsock, packet, src_address, src_port, rcode);
+ nbtd_name_registration_reply(nbtsock, packet, src, rcode);
}
@@ -174,7 +174,7 @@ done:
*/
static void nbtd_winsserver_query(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *packet,
- const char *src_address, int src_port)
+ const struct nbt_peer_socket *src)
{
struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private,
struct nbtd_interface);
@@ -184,11 +184,11 @@ static void nbtd_winsserver_query(struct nbt_name_socket *nbtsock,
rec = winsdb_load(winssrv, name, packet);
if (rec == NULL || rec->state != WINS_REC_ACTIVE) {
- nbtd_negative_name_query_reply(nbtsock, packet, src_address, src_port);
+ nbtd_negative_name_query_reply(nbtsock, packet, src);
return;
}
- nbtd_name_query_reply(nbtsock, packet, src_address, src_port, name,
+ nbtd_name_query_reply(nbtsock, packet, src, name,
0, rec->nb_flags, rec->addresses);
}
@@ -197,7 +197,7 @@ static void nbtd_winsserver_query(struct nbt_name_socket *nbtsock,
*/
static void nbtd_winsserver_release(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *packet,
- const char *src_address, int src_port)
+ const struct nbt_peer_socket *src)
{
struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private,
struct nbtd_interface);
@@ -214,7 +214,7 @@ static void nbtd_winsserver_release(struct nbt_name_socket *nbtsock,
/* we only allow releases from an owner - other releases are
silently ignored */
- if (str_list_check(rec->addresses, src_address)) {
+ if (str_list_check(rec->addresses, src->addr)) {
const char *address = packet->additional[0].rdata.netbios.addresses[0].ipaddr;
DEBUG(4,("WINS: released name %s at %s\n", nbt_name_string(rec, rec->name), address));
@@ -227,7 +227,7 @@ static void nbtd_winsserver_release(struct nbt_name_socket *nbtsock,
done:
/* we match w2k3 by always giving a positive reply to name releases. */
- nbtd_name_release_reply(nbtsock, packet, src_address, src_port, NBT_RCODE_OK);
+ nbtd_name_release_reply(nbtsock, packet, src, NBT_RCODE_OK);
}
@@ -236,7 +236,7 @@ done:
*/
void nbtd_winsserver_request(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *packet,
- const char *src_address, int src_port)
+ const struct nbt_peer_socket *src)
{
struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private,
struct nbtd_interface);
@@ -247,18 +247,18 @@ void nbtd_winsserver_request(struct nbt_name_socket *nbtsock,
switch (packet->operation & NBT_OPCODE) {
case NBT_OPCODE_QUERY:
- nbtd_winsserver_query(nbtsock, packet, src_address, src_port);
+ nbtd_winsserver_query(nbtsock, packet, src);
break;
case NBT_OPCODE_REGISTER:
case NBT_OPCODE_REFRESH:
case NBT_OPCODE_REFRESH2:
case NBT_OPCODE_MULTI_HOME_REG:
- nbtd_winsserver_register(nbtsock, packet, src_address, src_port);
+ nbtd_winsserver_register(nbtsock, packet, src);
break;
case NBT_OPCODE_RELEASE:
- nbtd_winsserver_release(nbtsock, packet, src_address, src_port);
+ nbtd_winsserver_release(nbtsock, packet, src);
break;
}
diff --git a/source4/nbt_server/wins/winswack.c b/source4/nbt_server/wins/winswack.c
index 8c7841d095..c9f102fdc8 100644
--- a/source4/nbt_server/wins/winswack.c
+++ b/source4/nbt_server/wins/winswack.c
@@ -30,8 +30,7 @@ struct wack_state {
struct nbt_name_socket *nbtsock;
struct nbt_name_packet *request_packet;
struct winsdb_record *rec;
- const char *src_address;
- int src_port;
+ struct nbt_peer_socket src;
const char **owner_addresses;
const char *reg_address;
struct nbt_name_query query;
@@ -44,9 +43,9 @@ struct wack_state {
static void wins_wack_deny(struct wack_state *state)
{
nbtd_name_registration_reply(state->nbtsock, state->request_packet,
- state->src_address, state->src_port, NBT_RCODE_ACT);
- DEBUG(4,("WINS: denied name registration request for %s from %s\n",
- nbt_name_string(state, state->rec->name), state->src_address));
+ &state->src, NBT_RCODE_ACT);
+ DEBUG(4,("WINS: denied name registration request for %s from %s:%d\n",
+ nbt_name_string(state, state->rec->name), state->src.addr, state->src.port));
talloc_free(state);
}
@@ -68,7 +67,7 @@ static void wins_wack_allow(struct wack_state *state)
}
nbtd_name_registration_reply(state->nbtsock, state->request_packet,
- state->src_address, state->src_port, NBT_RCODE_OK);
+ &state->src, NBT_RCODE_OK);
rec->addresses = str_list_add(rec->addresses, state->reg_address);
if (rec->addresses == NULL) goto failed;
@@ -77,7 +76,7 @@ static void wins_wack_allow(struct wack_state *state)
if (now + ttl > rec->expire_time) {
rec->expire_time = now + ttl;
}
- rec->registered_by = state->src_address;
+ rec->registered_by = state->src.addr;
winsdb_modify(state->winssrv, rec);
@@ -158,7 +157,7 @@ failed:
void wins_register_wack(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *packet,
struct winsdb_record *rec,
- const char *src_address, int src_port)
+ const struct nbt_peer_socket *src)
{
struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private,
struct nbtd_interface);
@@ -175,11 +174,11 @@ void wins_register_wack(struct nbt_name_socket *nbtsock,
state->nbtsock = nbtsock;
state->request_packet = talloc_steal(state, packet);
state->rec = talloc_steal(state, rec);
- state->src_port = src_port;
state->owner_addresses = rec->addresses;
state->reg_address = packet->additional[0].rdata.netbios.addresses[0].ipaddr;
- state->src_address = talloc_strdup(state, src_address);
- if (state->src_address == NULL) goto failed;
+ state->src.port = src->port;
+ state->src.addr = talloc_strdup(state, src->addr);
+ if (state->src.addr == NULL) goto failed;
/* setup a name query to the first address */
state->query.in.name = *rec->name;
@@ -198,7 +197,7 @@ void wins_register_wack(struct nbt_name_socket *nbtsock,
/* send a WACK to the client, specifying the maximum time it could
take to check with the owner, plus some slack */
ttl = 5 + 4 * str_list_length(rec->addresses);
- nbtd_wack_reply(nbtsock, packet, src_address, src_port, ttl);
+ nbtd_wack_reply(nbtsock, packet, src, ttl);
req = nbt_name_query_send(nbtsock, &state->query);
if (req == NULL) goto failed;
@@ -209,5 +208,5 @@ void wins_register_wack(struct nbt_name_socket *nbtsock,
failed:
talloc_free(state);
- nbtd_name_registration_reply(nbtsock, packet, src_address, src_port, NBT_RCODE_SVR);
+ nbtd_name_registration_reply(nbtsock, packet, src, NBT_RCODE_SVR);
}
diff --git a/source4/torture/nbt/dgram.c b/source4/torture/nbt/dgram.c
index ded2b49ea8..f63ada51ae 100644
--- a/source4/torture/nbt/dgram.c
+++ b/source4/torture/nbt/dgram.c
@@ -35,18 +35,18 @@
*/
static void netlogon_handler(struct dgram_mailslot_handler *dgmslot,
struct nbt_dgram_packet *packet,
- const char *src_address, int src_port)
+ const struct nbt_peer_socket *src)
{
NTSTATUS status;
struct nbt_netlogon_packet netlogon;
int *replies = dgmslot->private;
- printf("netlogon reply from %s:%d\n", src_address, src_port);
+ printf("netlogon reply from %s:%d\n", src->addr, src->port);
status = dgram_mailslot_netlogon_parse(dgmslot, dgmslot, packet, &netlogon);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to parse netlogon packet from %s:%d\n",
- src_address, src_port);
+ src->addr, src->port);
return;
}
@@ -62,6 +62,7 @@ static BOOL nbt_test_netlogon(TALLOC_CTX *mem_ctx,
{
struct dgram_mailslot_handler *dgmslot;
struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(mem_ctx, NULL);
+ struct nbt_peer_socket dest;
const char *myaddress = talloc_strdup(dgmsock, iface_best_ip(address));
struct nbt_netlogon_packet logon;
struct nbt_name myname;
@@ -81,7 +82,6 @@ static BOOL nbt_test_netlogon(TALLOC_CTX *mem_ctx,
/* setup a temporary mailslot listener for replies */
dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC,
netlogon_handler, &replies);
-
ZERO_STRUCT(logon);
logon.command = NETLOGON_QUERY_FOR_PDC;
@@ -94,14 +94,15 @@ static BOOL nbt_test_netlogon(TALLOC_CTX *mem_ctx,
make_nbt_name_client(&myname, TEST_NAME);
- status = dgram_mailslot_netlogon_send(dgmsock, &name, address,
- 0, &myname, &logon);
+ dest.port = 0;
+ dest.addr = address;
+ status = dgram_mailslot_netlogon_send(dgmsock, &name, &dest,
+ &myname, &logon);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to send netlogon request - %s\n", nt_errstr(status));
goto failed;
}
-
while (timeval_elapsed(&tv) < 5 && replies == 0) {
event_loop_once(dgmsock->event_ctx);
}
@@ -121,6 +122,7 @@ static BOOL nbt_test_netlogon2(TALLOC_CTX *mem_ctx,
{
struct dgram_mailslot_handler *dgmslot;
struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(mem_ctx, NULL);
+ struct nbt_peer_socket dest;
const char *myaddress = talloc_strdup(dgmsock, iface_best_ip(address));
struct nbt_netlogon_packet logon;
struct nbt_name myname;
@@ -154,8 +156,10 @@ static BOOL nbt_test_netlogon2(TALLOC_CTX *mem_ctx,
make_nbt_name_client(&myname, TEST_NAME);
- status = dgram_mailslot_netlogon_send(dgmsock, &name, address,
- 0, &myname, &logon);
+ dest.port = 0;
+ dest.addr = address;
+ status = dgram_mailslot_netlogon_send(dgmsock, &name, &dest,
+ &myname, &logon);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to send netlogon request - %s\n", nt_errstr(status));
goto failed;
@@ -180,18 +184,18 @@ failed:
*/
static void ntlogon_handler(struct dgram_mailslot_handler *dgmslot,
struct nbt_dgram_packet *packet,
- const char *src_address, int src_port)
+ const struct nbt_peer_socket *src)
{
NTSTATUS status;
struct nbt_ntlogon_packet ntlogon;
int *replies = dgmslot->private;
- printf("ntlogon reply from %s:%d\n", src_address, src_port);
+ printf("ntlogon reply from %s:%d\n", src->addr, src->port);
status = dgram_mailslot_ntlogon_parse(dgmslot, dgmslot, packet, &ntlogon);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to parse ntlogon packet from %s:%d\n",
- src_address, src_port);
+ src->addr, src->port);
return;
}
@@ -207,6 +211,7 @@ static BOOL nbt_test_ntlogon(TALLOC_CTX *mem_ctx,
{
struct dgram_mailslot_handler *dgmslot;
struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(mem_ctx, NULL);
+ struct nbt_peer_socket dest;
const char *myaddress = talloc_strdup(dgmsock, iface_best_ip(address));
struct nbt_ntlogon_packet logon;
struct nbt_name myname;
@@ -255,9 +260,10 @@ static BOOL nbt_test_ntlogon(TALLOC_CTX *mem_ctx,
make_nbt_name_client(&myname, TEST_NAME);
- status = dgram_mailslot_ntlogon_send(dgmsock, DGRAM_DIRECT_UNIQUE,
- &name, address,
- 0, &myname, &logon);
+ dest.port = 0;
+ dest.addr = address;
+ status = dgram_mailslot_ntlogon_send(dgmsock, &name, &dest,
+ &myname, &logon);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to send ntlogon request - %s\n", nt_errstr(status));
goto failed;