Commit bdf81033 authored by Michal Humpula's avatar Michal Humpula Committed by Marcin Siodelski
Browse files

[github23] Select client port for DHCPINFORM message.

parent 9c77c5bc
......@@ -1777,14 +1777,14 @@ Dhcpv4Srv::adjustIfaceData(Dhcpv4Exchange& ex) {
Pkt4Ptr response = ex.getResponse();
// For the non-relayed message, the destination port is the client's port.
// For the relayed message, the server/relay port is a destination.
// For the relayed message, the server/relay port is a destination unless
// the message is DHCPINFORM.
// Note that the call to this function may throw if invalid combination
// of hops and giaddr is found (hops = 0 if giaddr = 0 and hops != 0 if
// giaddr != 0). The exception will propagate down and eventually cause the
// packet to be discarded.
response->setRemotePort(query->isRelayed() ? DHCP4_SERVER_PORT :
const bool server_port = query->isRelayed() && ((query->getType() == DHCPINFORM) ? query->getCiaddr().isV4Zero() : true);
response->setRemotePort(server_port ? DHCP4_SERVER_PORT : DHCP4_CLIENT_PORT);
IOAddress local_addr = query->getLocalAddr();
......@@ -303,6 +303,8 @@ TEST_F(InformTest, relayedClient) {
EXPECT_EQ(IOAddress(""), resp->getLocalAddr());
// Response is unicast to the client, so it must not be relayed.
EXPECT_EQ(DHCP4_CLIENT_PORT, resp->getLocalPort());
EXPECT_EQ(DHCP4_SERVER_PORT, resp->getRemotePort());
// Make sure that the server id is present.
EXPECT_EQ("", client.config_.serverid_.toText());
// Make sure that the Routers option has been received.
......@@ -342,6 +344,8 @@ TEST_F(InformTest, relayedClientNoCiaddr) {
EXPECT_EQ(IOAddress(""), resp->getLocalAddr());
EXPECT_EQ(IOAddress(""), resp->getGiaddr());
EXPECT_EQ(1, resp->getHops());
EXPECT_EQ(DHCP4_SERVER_PORT, resp->getLocalPort());
EXPECT_EQ(DHCP4_SERVER_PORT, resp->getRemotePort());
// In the case when the client didn't set the ciaddr and the message
// was received via relay the server sets the Broadcast flag to help
// the relay forwarding the message (without yiaddr) to the client.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment