> but why we must need this parameters, it is the next server ip
> address.

Yes, we probably should prefer the 'server identifier' attribute instead
of the 'siaddr' to send the REQUEST to.

Please try the attached patch. It is completely untested, though.

Regards
Martin
>From e3bde0ef825b8b1e5368e2f4a3f04c8c21250766 Mon Sep 17 00:00:00 2001
From: Martin Willi <[email protected]>
Date: Mon, 18 Oct 2010 12:31:48 +0200
Subject: [PATCH] Prefer the 'server identifier' attribute address to send DHCP requests to

---
 src/libcharon/plugins/dhcp/dhcp_socket.c |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/libcharon/plugins/dhcp/dhcp_socket.c b/src/libcharon/plugins/dhcp/dhcp_socket.c
index 36678f0..e1e83d6 100644
--- a/src/libcharon/plugins/dhcp/dhcp_socket.c
+++ b/src/libcharon/plugins/dhcp/dhcp_socket.c
@@ -463,8 +463,6 @@ static void handle_offer(private_dhcp_socket_t *this, dhcp_t *dhcp, int optlen)
 
 	offer = host_create_from_chunk(AF_INET,
 					chunk_from_thing(dhcp->your_address), 0);
-	server = host_create_from_chunk(AF_INET,
-					chunk_from_thing(dhcp->server_address), DHCP_SERVER_PORT);
 
 	this->mutex->lock(this->mutex);
 	enumerator = this->discover->create_enumerator(this->discover);
@@ -472,11 +470,8 @@ static void handle_offer(private_dhcp_socket_t *this, dhcp_t *dhcp, int optlen)
 	{
 		if (transaction->get_id(transaction) == dhcp->transaction_id)
 		{
-			DBG1(DBG_CFG, "received DHCP OFFER %H from %H", offer, server);
 			this->discover->remove_at(this->discover, enumerator);
 			this->request->insert_last(this->request, transaction);
-			transaction->set_address(transaction, offer->clone(offer));
-			transaction->set_server(transaction, server->clone(server));
 			break;
 		}
 	}
@@ -505,9 +500,22 @@ static void handle_offer(private_dhcp_socket_t *this, dhcp_t *dhcp, int optlen)
 						chunk_create((char*)&option->data[pos], 4));
 				}
 			}
+			if (option->type == DHCP_SERVER_ID && option->len == 4)
+			{
+				server = host_create_from_chunk(AF_INET,
+							chunk_create(option->data, 4), DHCP_SERVER_PORT);
+			}
 			optlen -= optsize;
 			optpos += optsize;
 		}
+		if (!server)
+		{
+			server = host_create_from_chunk(AF_INET,
+				chunk_from_thing(dhcp->server_address), DHCP_SERVER_PORT);
+		}
+		DBG1(DBG_CFG, "received DHCP OFFER %H from %H", offer, server);
+		transaction->set_address(transaction, offer->clone(offer));
+		transaction->set_server(transaction, server->clone(server));
 	}
 	this->mutex->unlock(this->mutex);
 	this->condvar->broadcast(this->condvar);
-- 
1.7.1

_______________________________________________
Users mailing list
[email protected]
https://lists.strongswan.org/mailman/listinfo/users

Reply via email to