Bug 3411 - Failed to bind to 255.255.255.255:138 - NT_STATUS_ADDRESS_NOT_ASSOCIATED
Summary: Failed to bind to 255.255.255.255:138 - NT_STATUS_ADDRESS_NOT_ASSOCIATED
Status: RESOLVED FIXED
Alias: None
Product: Samba 4.0
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: All FreeBSD
: P3 major (vote)
Target Milestone: ---
Assignee: Stefan Metzmacher
QA Contact: Andrew Bartlett
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-16 01:44 UTC by Oleg Sharoiko
Modified: 2006-01-17 00:48 UTC (History)
2 users (show)

See Also:


Attachments
Ups. Reformatting is not good for patches. (3.10 KB, patch)
2006-01-16 01:51 UTC, Oleg Sharoiko
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Oleg Sharoiko 2006-01-16 01:44:55 UTC
I've mailed samba-technical a week ago about this bug. Since that time code has changed so I provide new patch against current code.

Samba4 gives me an error (FreeBSD 6.0):

[Mon Jan 16 10:39:46 2006 MSK, 0 nbt_server/dgram/request.c:86:nbtd_dgram_setup()]
Failed to bind to 255.255.255.255:138 - NT_STATUS_ADDRESS_NOT_ASSOCIATED
[Mon Jan 16 10:39:46 2006 MSK, 0 nbt_server/interfaces.c:179:nbtd_add_socket()]
Failed to setup dgram listen on 0.0.0.0 - NT_STATUS_ADDRESS_NOT_ASSOCIATED
[Mon Jan 16 10:39:46 2006 MSK, 0 smbd/service_task.c:36:task_server_terminate()]
task_server_terminate: [nbtd failed to setup interfaces]

This happens if 'bind interfaces only' is not set, when nbtd_dgram_setup() 
is called for pseudo interface 0.0.0.0. In this case nbtd_dgram_setup() 
tries to bind to 255.255.255.255, which is a broadcast address of that 
pseudo interface. Shouldn't nbtd_dgram_setup() have a check to not bind to 
broadcast address of pseudo interface similar to the check implemented in 
nbtd_add_socket() ?

Something like this:

Index: nbt_server/dgram/request.c
===================================================================
--- nbt_server/dgram/request.c	(revision 12957)
+++ nbt_server/dgram/request.c	(working copy)
@@ -56,7 +56,7 @@
 */
 NTSTATUS nbtd_dgram_setup(struct nbtd_interface *iface, const char *bind_address)
 {
-	struct nbt_dgram_socket *bcast_dgmsock;
+	struct nbt_dgram_socket *bcast_dgmsock = NULL;
 	struct nbtd_server *nbtsrv = iface->nbtsrv;
 	struct socket_address *bcast_addr, *bind_addr;
 	NTSTATUS status;
@@ -69,31 +69,33 @@
 	}
 
 	/* listen for broadcasts on port 138 */
-	bcast_dgmsock = nbt_dgram_socket_init(iface, nbtsrv->task->event_ctx);
-	if (!bcast_dgmsock) {
-		talloc_free(tmp_ctx);
-		return NT_STATUS_NO_MEMORY;
-	}
+	if (strcmp(iface->netmask, "0.0.0.0") != 0) {
+		bcast_dgmsock = nbt_dgram_socket_init(iface,
+						      nbtsrv->task->event_ctx);
+		if (!bcast_dgmsock) {
+			talloc_free(tmp_ctx);
+			return NT_STATUS_NO_MEMORY;
+		}
 	
-	bcast_addr = socket_address_from_strings(tmp_ctx, bcast_dgmsock->sock->backend_name, 
-						 iface->bcast_address, 
-						 lp_dgram_port());
+		bcast_addr = socket_address_from_strings(tmp_ctx,
+					bcast_dgmsock->sock->backend_name, 
+					iface->bcast_address, 
+				 	lp_dgram_port());
 
-	status = socket_listen(bcast_dgmsock->sock, bcast_addr, 0, 0);
-	if (!NT_STATUS_IS_OK(status)) {
-		talloc_free(tmp_ctx);
-		DEBUG(0,("Failed to bind to %s:%d - %s\n", 
-			 iface->bcast_address, lp_dgram_port(), nt_errstr(status)));
-		return status;
+		status = socket_listen(bcast_dgmsock->sock, bcast_addr, 0, 0);
+		if (!NT_STATUS_IS_OK(status)) {
+			talloc_free(tmp_ctx);
+			DEBUG(0,("Failed to bind to %s:%d - %s\n", 
+			 	iface->bcast_address, lp_dgram_port(),
+				nt_errstr(status)));
+			return status;
+		}
+		talloc_free(bcast_addr);
+	
+		dgram_set_incoming_handler(bcast_dgmsock, dgram_request_handler,
+					   iface);
 	}
-	talloc_free(bcast_addr);
-	
-	dgram_set_incoming_handler(bcast_dgmsock, dgram_request_handler, iface);
 
-	bind_addr = socket_address_from_strings(tmp_ctx, bcast_dgmsock->sock->backend_name, 
-						bind_address, 
-						lp_dgram_port());
-
 	/* listen for unicasts on port 138 */
 	iface->dgmsock = nbt_dgram_socket_init(iface, nbtsrv->task->event_ctx);
 	if (!iface->dgmsock) {
@@ -101,6 +103,11 @@
 		return NT_STATUS_NO_MEMORY;
 	}
 
+	bind_addr = socket_address_from_strings(tmp_ctx,
+					iface->dgmsock->sock->backend_name, 
+					bind_address, 
+					lp_dgram_port());
+
 	status = socket_listen(iface->dgmsock->sock, bind_addr, 0, 0);
 	if (!NT_STATUS_IS_OK(status)) {
 		talloc_free(tmp_ctx);
@@ -121,10 +128,12 @@
 		   we need */
 		struct dgram_mailslot_handler *dgmslot;
 
-		dgmslot = dgram_mailslot_listen(bcast_dgmsock, 
-						mailslot_handlers[i].mailslot_name,
-						mailslot_handlers[i].handler, iface);
-		NT_STATUS_HAVE_NO_MEMORY(dgmslot);
+		if (bcast_dgmsock != NULL) {
+			dgmslot = dgram_mailslot_listen(bcast_dgmsock, 
+					mailslot_handlers[i].mailslot_name,
+					mailslot_handlers[i].handler, iface);
+			NT_STATUS_HAVE_NO_MEMORY(dgmslot);
+		}
 
 		dgmslot = dgram_mailslot_listen(iface->dgmsock, 
 						mailslot_handlers[i].mailslot_name,
Comment 1 Oleg Sharoiko 2006-01-16 01:51:04 UTC
Created attachment 1688 [details]
Ups. Reformatting is not good for patches.

It looks like browser formatting has corrupted the patch, so I'm attaching it a a file.
Comment 2 Stefan Metzmacher 2006-01-16 07:07:06 UTC
should be fixed in rev 12958,
please test
Comment 3 Oleg Sharoiko 2006-01-17 00:48:28 UTC
It works. Thanks!