Skip to content

Commit

Permalink
dhcp: Move log messages for received packets
Browse files Browse the repository at this point in the history
This way they are logged in the context of the corresponding IKE_SA.

Closes #417.
  • Loading branch information
tobiasbrunner committed Jun 8, 2021
1 parent 4e29d6f commit ae71f83
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/libcharon/plugins/dhcp/dhcp_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ METHOD(dhcp_socket_t, enroll, dhcp_transaction_t*,
DBG1(DBG_CFG, "DHCP DISCOVER timed out");
return NULL;
}
DBG1(DBG_CFG, "received DHCP OFFER %H from %H",
transaction->get_address(transaction),
transaction->get_server(transaction));

try = 1;
while (try <= DHCP_TRIES && request(this, transaction))
Expand All @@ -437,6 +440,8 @@ METHOD(dhcp_socket_t, enroll, dhcp_transaction_t*,
return NULL;
}
this->mutex->unlock(this->mutex);
DBG1(DBG_CFG, "received DHCP ACK for %H",
transaction->get_address(transaction));

return transaction;
}
Expand Down Expand Up @@ -550,7 +555,6 @@ static void handle_offer(private_dhcp_socket_t *this, dhcp_t *dhcp, int optlen)
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);
}
Expand All @@ -566,18 +570,13 @@ static void handle_ack(private_dhcp_socket_t *this, dhcp_t *dhcp, int optlen)
{
dhcp_transaction_t *transaction;
enumerator_t *enumerator;
host_t *offer;

offer = host_create_from_chunk(AF_INET,
chunk_from_thing(dhcp->your_address), 0);

this->mutex->lock(this->mutex);
enumerator = this->request->create_enumerator(this->request);
while (enumerator->enumerate(enumerator, &transaction))
{
if (transaction->get_id(transaction) == dhcp->transaction_id)
{
DBG1(DBG_CFG, "received DHCP ACK for %H", offer);
this->request->remove_at(this->request, enumerator);
this->completed->insert_last(this->completed, transaction);
break;
Expand All @@ -586,7 +585,6 @@ static void handle_ack(private_dhcp_socket_t *this, dhcp_t *dhcp, int optlen)
enumerator->destroy(enumerator);
this->mutex->unlock(this->mutex);
this->condvar->broadcast(this->condvar);
offer->destroy(offer);
}

/**
Expand Down

0 comments on commit ae71f83

Please sign in to comment.