diff options
-rw-r--r-- | source4/nbt_server/interfaces.c | 24 | ||||
-rw-r--r-- | source4/nbt_server/irpc.c | 9 |
2 files changed, 27 insertions, 6 deletions
diff --git a/source4/nbt_server/interfaces.c b/source4/nbt_server/interfaces.c index 23276123d5..4ef2afb8ee 100644 --- a/source4/nbt_server/interfaces.c +++ b/source4/nbt_server/interfaces.c @@ -286,3 +286,27 @@ failed: talloc_free(ret); return NULL; } + + +/* + find the interface to use for sending a outgoing request +*/ +struct nbtd_interface *nbtd_find_interface(struct nbtd_server *nbtd_server, + const char *address) +{ + struct nbtd_interface *iface; + /* try to find a exact match */ + for (iface=nbtd_server->interfaces;iface;iface=iface->next) { + if (iface_same_net(address, iface->ip_address, iface->netmask)) { + return iface; + } + } + + /* no exact match, if we have the broadcast interface, use that */ + if (nbtd_server->bcast_interface) { + return nbtd_server->bcast_interface; + } + + /* fallback to first interface */ + return nbtd_server->interfaces; +} diff --git a/source4/nbt_server/irpc.c b/source4/nbt_server/irpc.c index 75a950b5c4..0cd65453a4 100644 --- a/source4/nbt_server/irpc.c +++ b/source4/nbt_server/irpc.c @@ -115,11 +115,10 @@ static NTSTATUS nbtd_getdcname(struct irpc_message *msg, { struct nbtd_server *server = talloc_get_type(msg->private, struct nbtd_server); - + struct nbtd_interface *iface = nbtd_find_interface(server, req->in.ip_address); struct getdc_state *s; struct nbt_ntlogon_packet p; struct nbt_ntlogon_sam_logon *r; - struct nbt_dgram_socket *sock; struct nbt_name src, dst; struct nbt_peer_socket dest; struct dgram_mailslot_handler *handler; @@ -127,15 +126,13 @@ static NTSTATUS nbtd_getdcname(struct irpc_message *msg, DEBUG(0, ("nbtd_getdcname called\n")); - sock = server->interfaces[0].dgmsock; - s = talloc(msg, struct getdc_state); NT_STATUS_HAVE_NO_MEMORY(s); s->msg = msg; s->req = req; - handler = dgram_mailslot_temp(sock, NBT_MAILSLOT_GETDC, + handler = dgram_mailslot_temp(iface->dgmsock, NBT_MAILSLOT_GETDC, getdc_recv_ntlogon_reply, s); NT_STATUS_HAVE_NO_MEMORY(handler); @@ -157,7 +154,7 @@ static NTSTATUS nbtd_getdcname(struct irpc_message *msg, dest.addr = req->in.ip_address; dest.port = 138; - status = dgram_mailslot_ntlogon_send(sock, DGRAM_DIRECT_GROUP, + status = dgram_mailslot_ntlogon_send(iface->dgmsock, DGRAM_DIRECT_GROUP, &dst, &dest, &src, &p); if (!NT_STATUS_IS_OK(status)) { |