From: Michal Humpula Date: Mon, 13 Jun 2016 15:50:04 +0000 (+0200) Subject: [github23] Select client port for DHCPINFORM message. X-Git-Tag: trac4551_base~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bdf81033b620a0f7292cd44f64268932fcec8169;p=thirdparty%2Fkea.git [github23] Select client port for DHCPINFORM message. --- diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 7f598ef007..6faab3dca4 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -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 : - DHCP4_CLIENT_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(); diff --git a/src/bin/dhcp4/tests/inform_unittest.cc b/src/bin/dhcp4/tests/inform_unittest.cc index dd75f4f3a3..e00f7c78b5 100644 --- a/src/bin/dhcp4/tests/inform_unittest.cc +++ b/src/bin/dhcp4/tests/inform_unittest.cc @@ -303,6 +303,8 @@ TEST_F(InformTest, relayedClient) { EXPECT_EQ(IOAddress("192.0.2.56"), resp->getLocalAddr()); // Response is unicast to the client, so it must not be relayed. EXPECT_FALSE(resp->isRelayed()); + EXPECT_EQ(DHCP4_CLIENT_PORT, resp->getLocalPort()); + EXPECT_EQ(DHCP4_SERVER_PORT, resp->getRemotePort()); // Make sure that the server id is present. EXPECT_EQ("10.0.0.1", client.config_.serverid_.toText()); // Make sure that the Routers option has been received. @@ -342,6 +344,8 @@ TEST_F(InformTest, relayedClientNoCiaddr) { EXPECT_EQ(IOAddress("192.0.2.2"), resp->getLocalAddr()); EXPECT_EQ(IOAddress("192.0.2.2"), 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.