Index: src/servers/net/DHCPClient.cpp
===================================================================
--- src/servers/net/DHCPClient.cpp	(revision 28736)
+++ src/servers/net/DHCPClient.cpp	(working copy)
@@ -21,6 +21,27 @@
 #include <sys/time.h>
 
 
+#define LND do { ktrace_printf("DHCP: %s: %s: %d\n", __FILE__, __func__, __LINE__); } while(0)
+
+void trace_dhcp_state(dhcp_state state)
+{
+	char *state_name=NULL;
+	switch(state)
+	{
+		case INIT: state_name = "INIT"; break;
+		case REQUESTING: state_name = "REQUESTING"; break;
+		case BOUND: state_name = "BOUND"; break;
+		case RENEWAL: state_name="RENEWAL"; break;
+		case REBINDING: state_name="REBINDING"; break;
+		case ACKNOWLEDGED: state_name="ACKNOWLEDGED"; break;
+		default: break;
+	}
+	if (state_name == NULL)
+		ktrace_printf("DHCP: state 0x%x\n", (unsigned)state);
+	else
+		ktrace_printf("DHCP: state %s\n", state_name);
+}
+
 // See RFC 2131 for DHCP, see RFC 1533 for BOOTP/DHCP options
 
 #define DHCP_CLIENT_PORT	68
@@ -336,22 +357,27 @@
 	fRunner(NULL),
 	fLeaseTime(0)
 {
+	LND;
 	fStartTime = system_time();
 	fTransactionID = (uint32)fStartTime;
 
 	fStatus = get_mac_address(device, fMAC);
-	if (fStatus < B_OK)
+	if (fStatus < B_OK) {
+		LND;
 		return;
+	}
 
 	memset(&fServer, 0, sizeof(struct sockaddr_in));
 	fServer.sin_family = AF_INET;
 	fServer.sin_len = sizeof(struct sockaddr_in);
 	fServer.sin_port = htons(DHCP_SERVER_PORT);
+	LND;
 }
 
 
 DHCPClient::~DHCPClient()
 {
+	LND;
 	if (fStatus != B_OK)
 		return;
 
@@ -374,18 +400,29 @@
 status_t
 DHCPClient::Initialize()
 {
+	LND;
+	trace_dhcp_state(INIT);
 	fStatus = _Negotiate(INIT);
 	printf("DHCP for %s, status: %s\n", fDevice.String(), strerror(fStatus));
 	return fStatus;
 }
 
-
 status_t
 DHCPClient::_Negotiate(dhcp_state state)
 {
+	LND;
+	ktrace_printf("DHCP: %d: now %lld, fLeaseTime %lld, fRebindingTime %lld, fRenewalTime %lld\n",__LINE__, system_time(), fLeaseTime, fRebindingTime, fRenewalTime);
+	trace_dhcp_state(state);
+	if (state != INIT
+		&& state != REBINDING
+		&& state != RENEWAL)
+		fprintf(stderr, "DHCP client: negotiating: unexpected state %d\n", state);
+
 	int socket = ::socket(AF_INET, SOCK_DGRAM, 0);
-	if (socket < 0)
+	if (socket < 0) {
+		LND;
 		return errno;
+	}
 
 	sockaddr_in local;
 	memset(&local, 0, sizeof(struct sockaddr_in));
@@ -396,6 +433,7 @@
 
 	if (bind(socket, (struct sockaddr *)&local, sizeof(local)) < 0) {
 		close(socket);
+		LND;
 		return errno;
 	}
 
@@ -410,15 +448,18 @@
 	setsockopt(socket, SOL_SOCKET, SO_BROADCAST, &option, sizeof(option));
 
 	if (state == INIT) {
+		LND;
 		// The local interface does not have an address yet, bind the socket
 		// to the device directly.
 		int linkSocket = ::socket(AF_LINK, SOCK_DGRAM, 0);
 		if (linkSocket >= 0) {
+			LND;
 			// we need to know the index of the device to be able to bind to it
 			ifreq request;
 			prepare_request(request, fDevice.String());
 			if (ioctl(linkSocket, SIOCGIFINDEX, &request, sizeof(struct ifreq))
 					== 0) {
+				LND;
 				setsockopt(socket, SOL_SOCKET, SO_BINDTODEVICE,
 					&request.ifr_index, sizeof(int));
 			}
@@ -448,18 +489,25 @@
 		state != RENEWAL ? broadcast : fServer);
 	if (status < B_OK) {
 		close(socket);
+		LND;
 		return status;
 	}
 
 	// receive loop until we've got an offer and acknowledged it
 
+	LND;
+
 	while (state != ACKNOWLEDGED) {
+		LND;
+		trace_dhcp_state(state);
 		char buffer[2048];
 		ssize_t bytesReceived = recvfrom(socket, buffer, sizeof(buffer),
 			0, NULL, NULL);
 		if (bytesReceived < 0 && errno == B_TIMED_OUT) {
+			LND;
 			// depending on the state, we'll just try again
 			if (!_TimeoutShift(socket, timeout, tries)) {
+				LND;
 				close(socket);
 				return B_TIMED_OUT;
 			}
@@ -467,20 +515,24 @@
 			if (state == INIT)
 				status = _SendMessage(socket, discover, broadcast);
 			else {
+				LND;
 				status = _SendMessage(socket, request, state != RENEWAL
 					? broadcast : fServer);
 			}
 
 			if (status < B_OK)
 				break;
+			LND;
 		} else if (bytesReceived < B_OK)
 			break;
+		LND;
 
 		dhcp_message *message = (dhcp_message *)buffer;
 		if (message->transaction_id != htonl(fTransactionID)
 			|| !message->HasOptions()
 			|| memcmp(message->mac_address, discover.mac_address,
 				discover.hardware_address_length)) {
+			LND;
 			// this message is not for us
 			continue;
 		}
@@ -488,14 +540,17 @@
 		switch (message->Type()) {
 			case DHCP_NONE:
 			default:
+				LND;
 				// ignore this message
 				break;
 
 			case DHCP_OFFER:
 			{
+				LND;
 				// first offer wins
 				if (state != INIT)
 					break;
+				LND;
 
 				// collect interface options
 
@@ -516,6 +571,7 @@
 
 				_ResetTimeout(socket, timeout, tries);
 				state = REQUESTING;
+				trace_dhcp_state(state);
 				_PrepareMessage(request, state);
 
 				status = _SendMessage(socket, request, broadcast);
@@ -526,9 +582,12 @@
 
 			case DHCP_ACK:
 			{
+				LND;
+				trace_dhcp_state(state);
 				if (state != REQUESTING && state != REBINDING
 					&& state != RENEWAL)
 					continue;
+				LND;
 
 				// TODO: we might want to configure the stuff, don't we?
 				BMessage address;
@@ -548,8 +607,10 @@
 			}
 
 			case DHCP_NACK:
+			LND;
 				if (state != REQUESTING)
 					continue;
+				LND;
 
 				// try again (maybe we should prefer other servers if this
 				// happens more than once)
@@ -559,16 +620,20 @@
 				break;
 		}
 	}
+	LND;
+	trace_dhcp_state(state);
 
 	close(socket);
 
 	if (status == B_OK && fLeaseTime > 0) {
+		LND;
 		// notify early enough when the lease is
 		if (fRenewalTime == 0)
 			fRenewalTime = fLeaseTime * 2/3;
 		if (fRebindingTime == 0)
 			fRebindingTime = fLeaseTime * 5/6;
 
+		LND;
 		_RestartLease(fRenewalTime);
 
 		bigtime_t now = system_time();
@@ -577,11 +642,15 @@
 		fRebindingTime += now;
 			// make lease times absolute
 	} else {
+		LND;
+		ktrace_printf("DHCP: %d: now %lld, fLeaseTime %lld, fRebindingTime %lld, fRenewalTime %lld\n",__LINE__, system_time(), fLeaseTime, fRebindingTime, fRenewalTime);
 		fLeaseTime = previousLeaseTime;
 		bigtime_t now = system_time();
 		fRenewalTime = (fLeaseTime - now) * 2/3 + now;
 		fRebindingTime = (fLeaseTime - now) * 5/6 + now;
+		ktrace_printf("DHCP: %d: now %lld, fLeaseTime %lld, fRebindingTime %lld, fRenewalTime %lld\n",__LINE__, system_time(), fLeaseTime, fRebindingTime, fRenewalTime);
 	}
+	LND;
 
 	return status;
 }
@@ -590,11 +659,13 @@
 void
 DHCPClient::_RestartLease(bigtime_t leaseTime)
 {
+	LND;
 	if (leaseTime == 0)
 		return;
+	ktrace_printf("DHCP: _RestartLease: leaseTime %lld\n", leaseTime);
 
 	BMessage lease(kMsgLeaseTime);
-	fRunner = new BMessageRunner(this, &lease, leaseTime, 1);
+	fRunner = new BMessageRunner(this, &lease, leaseTime+1000, 1);
 }
 
 
@@ -798,6 +869,8 @@
 DHCPClient::_CurrentState() const
 {
 	bigtime_t now = system_time();
+
+	ktrace_printf("DHCP: %d: now %lld, fLeaseTime %lld, fRebindingTime %lld, fRenewalTime %lld\n",__LINE__, system_time(), fLeaseTime, fRebindingTime, fRenewalTime);
 	
 	if (now > fLeaseTime || fStatus < B_OK)
 		return INIT;
@@ -819,6 +892,8 @@
 			dhcp_state state = _CurrentState();
 
 			bigtime_t next;
+			LND;
+			trace_dhcp_state(state);
 			if (_Negotiate(state) == B_OK) {
 				switch (state) {
 					case RENEWAL:
@@ -841,6 +916,7 @@
 				}
 			}
 
+			LND;
 			_RestartLease(next - system_time());
 			break;
 		}
Index: src/servers/net/NetServer.cpp
===================================================================
--- src/servers/net/NetServer.cpp	(revision 28736)
+++ src/servers/net/NetServer.cpp	(working copy)
@@ -37,7 +37,9 @@
 #include <string.h>
 #include <unistd.h>
 
+#define LND do { ktrace_printf("DHCP: %s: %s: %d\n", __FILE__, __func__, __LINE__); } while(0)
 
+
 static const char *kSignature = "application/x-vnd.haiku-net_server";
 
 
@@ -315,6 +317,7 @@
 			if (socket < 0)
 				break;
 
+			LND;
 			status_t status = _ConfigureInterface(socket, *message, true);
 
 			BMessage reply(B_REPLY);
@@ -485,6 +488,8 @@
 status_t
 NetServer::_ConfigureInterface(int socket, BMessage& interface, bool fromMessage)
 {
+	LND;
+
 	const char *device;
 	if (interface.FindString("device", &device) != B_OK)
 		return B_BAD_VALUE;
@@ -675,8 +680,10 @@
 		}
 	}
 
+	LND;
 	if (startAutoConfig) {
 		// start auto configuration
+		LND;
 		AutoconfigLooper* looper = new AutoconfigLooper(this, device);
 		looper->Run();
 
@@ -725,6 +732,8 @@
 	address.AddBool("auto config", true);
 	interface.AddMessage("address", &address);
 
+	LND;
+
 	return _ConfigureInterface(socket, interface);
 }
 
@@ -746,6 +755,7 @@
 			continue;
 
 		if (S_ISBLK(stat.st_mode) || S_ISCHR(stat.st_mode)) {
+			LND;
 			if (suggestedInterface != NULL
 				&& suggestedInterface->RemoveName("device") == B_OK
 				&& suggestedInterface->AddString("device", path.Path()) == B_OK
@@ -782,6 +792,7 @@
 			}
 		}
 
+		LND;
 		_ConfigureInterface(socket, interface);
 	}
 }
@@ -817,6 +828,7 @@
 		address.AddString("address", "127.0.0.1");
 		interface.AddMessage("address", &address);
 
+		LND;
 		_ConfigureInterface(socket, interface);
 	}
 
Index: src/servers/net/AutoconfigLooper.cpp
===================================================================
--- src/servers/net/AutoconfigLooper.cpp	(revision 28736)
+++ src/servers/net/AutoconfigLooper.cpp	(working copy)
@@ -18,7 +18,9 @@
 #include <sys/socket.h>
 #include <sys/sockio.h>
 
+#define LND do { ktrace_printf("DHCP: %s: %s: %d\n", __FILE__, __func__, __LINE__); } while(0)
 
+
 static const uint32 kMsgReadyToRun = 'rdyr';
 
 
@@ -27,6 +29,7 @@
 	fTarget(target),
 	fDevice(device)
 {
+	LND;
 	BMessage ready(kMsgReadyToRun);
 	PostMessage(&ready);
 }
@@ -40,9 +43,11 @@
 void
 AutoconfigLooper::_ReadyToRun()
 {
+	LND;
 	ifreq request;
 	if (!prepare_request(request, fDevice.String()))
 		return;
+	LND;
 
 	// set IFF_CONFIGURING flag on interface
 
@@ -58,6 +63,7 @@
 	close(socket);
 
 	// start with DHCP
+	LND;
 
 	DHCPClient* client = new DHCPClient(fTarget, fDevice.String());
 	AddHandler(client);
@@ -74,6 +80,7 @@
 	// TODO: have a look at zeroconf
 	// TODO: this could also be done add-on based
 
+	LND;
 	BMessage interface(kMsgConfigureInterface);
 	interface.AddString("device", fDevice.String());
 	interface.AddBool("auto", true);
