From: Francis Dupont Date: Sat, 23 Dec 2017 21:59:15 +0000 (+0100) Subject: [5404] Finished 4o6 code X-Git-Tag: trac5458a_base~19^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e4953a9c96db09fe5205c3d66eb4941ff046b92;p=thirdparty%2Fkea.git [5404] Finished 4o6 code --- diff --git a/src/bin/dhcp4/dhcp4_messages.mes b/src/bin/dhcp4/dhcp4_messages.mes index 05426d29e7..ddcb93bb13 100644 --- a/src/bin/dhcp4/dhcp4_messages.mes +++ b/src/bin/dhcp4/dhcp4_messages.mes @@ -176,11 +176,11 @@ a client's error or a server's purged database. % DHCP4_DHCP4O6_BAD_PACKET received malformed DHCPv4o6 packet: %1 A malformed DHCPv4o6 packet was received. -% DHCP4_DHCP4O6_PACKET_SEND %1: trying to send packet %2 (type %3) to %4 on interface %5 encapsulating %6: %7 (type %8) +% DHCP4_DHCP4O6_PACKET_SEND %1: trying to send packet %2 (type %3) to %4 port %5 on interface %6 encapsulating %7: %8 (type %9) The arguments specify the client identification information (HW address and client identifier), DHCPv6 message name and type, source IPv6 -address and interface name, DHCPv4 client identification, message -name and type. +address and port, and interface name, DHCPv4 client identification, +message name and type. % DHCP4_DHCP4O6_PACKET_SEND_FAIL %1: failed to send DHCPv4o6 packet: %2 This error is output if the IPv4 DHCP server fails to send an @@ -693,6 +693,6 @@ and will send DHCPNAK if the received message was DHCPREQUEST. The argument includes the client and the transaction identification information. -% DHCP6_DHCP4O6_PACKET_RECEIVED received DHCPv4o6 packet from DHCPv6 server (type %1) for %2 on interface %3 +% DHCP6_DHCP4O6_PACKET_RECEIVED received DHCPv4o6 packet from DHCPv6 server (type %1) for %2 port %3 on interface %4 This debug message is printed when the server is receiving a DHCPv4o6 from the DHCPv6 server over inter-process communication. diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index a834e30987..7bfcb39d17 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -205,10 +205,11 @@ Dhcpv4Exchange::initResponse4o6() { if (!query6->relay_info_.empty()) { resp6->copyRelayInfo(query6); } - // Copy interface and remote address + // Copy interface, and remote address and port resp6->setIface(query6->getIface()); resp6->setIndex(query6->getIndex()); resp6->setRemoteAddr(query6->getRemoteAddr()); + resp6->setRemotePort(query6->getRemotePort()); resp_.reset(new Pkt4o6(resp_, resp6)); } diff --git a/src/bin/dhcp4/dhcp4to6_ipc.cc b/src/bin/dhcp4/dhcp4to6_ipc.cc index b219207265..f3cfb2bdf1 100644 --- a/src/bin/dhcp4/dhcp4to6_ipc.cc +++ b/src/bin/dhcp4/dhcp4to6_ipc.cc @@ -66,6 +66,7 @@ void Dhcp4to6Ipc::handler() { LOG_DEBUG(packet4_logger, DBG_DHCP4_BASIC, DHCP6_DHCP4O6_PACKET_RECEIVED) .arg(static_cast(pkt->getType())) .arg(pkt->getRemoteAddr().toText()) + .arg(pkt->getRemotePort()) .arg(pkt->getIface()); } } catch (const std::exception& e) { @@ -156,6 +157,7 @@ void Dhcp4to6Ipc::handler() { .arg(rsp6->getName()) .arg(static_cast(rsp6->getType())) .arg(rsp6->getRemoteAddr()) + .arg(rsp6->getRemotePort()) .arg(rsp6->getIface()) .arg(rsp->getLabel()) .arg(rsp->getName()) diff --git a/src/bin/dhcp6/dhcp6_messages.mes b/src/bin/dhcp6/dhcp6_messages.mes index 0d6c9caebe..8a8173c504 100644 --- a/src/bin/dhcp6/dhcp6_messages.mes +++ b/src/bin/dhcp6/dhcp6_messages.mes @@ -205,7 +205,7 @@ received in Decline message. It's expected that the option will contain an address that is being declined. Specific information will be printed in a separate message. -% DHCP6_DHCP4O6_PACKET_RECEIVED received DHCPv4o6 packet from DHCPv4 server (type %1) for %2 on interface %3 +% DHCP6_DHCP4O6_PACKET_RECEIVED received DHCPv4o6 packet from DHCPv4 server (type %1) for %2 port %3 on interface %4 This debug message is printed when the server is receiving a DHCPv4o6 from the DHCPv4 server over inter-process communication. diff --git a/src/bin/dhcp6/dhcp6to4_ipc.cc b/src/bin/dhcp6/dhcp6to4_ipc.cc index 71759732f3..a3fa09120e 100644 --- a/src/bin/dhcp6/dhcp6to4_ipc.cc +++ b/src/bin/dhcp6/dhcp6to4_ipc.cc @@ -64,6 +64,7 @@ void Dhcp6to4Ipc::handler() { LOG_DEBUG(packet6_logger, DBG_DHCP6_BASIC, DHCP6_DHCP4O6_PACKET_RECEIVED) .arg(static_cast(pkt->getType())) .arg(pkt->getRemoteAddr().toText()) + .arg(pkt->getRemotePort()) .arg(pkt->getIface()); } } catch (const std::exception& e) { @@ -77,6 +78,9 @@ void Dhcp6to4Ipc::handler() { // Should we check it is a DHCPV6_DHCPV4_RESPONSE? + // Handle relay port + uint16_t relay_port = Dhcpv6Srv::testRelaySourcePort(pkt); + // The received message has been unpacked by the receive() function. This // method could have modified the message so it's better to pack() it // again because we'll be forwarding it to a client. @@ -89,7 +93,6 @@ void Dhcp6to4Ipc::handler() { // getType() always returns the type of internal message. uint8_t msg_type = buf[0]; if ((msg_type == DHCPV6_RELAY_FORW) || (msg_type == DHCPV6_RELAY_REPL)) { - uint16_t relay_port = Dhcpv6Srv::testRelaySourcePort(pkt); pkt->setRemotePort(relay_port ? relay_port : DHCP6_SERVER_PORT); } else { pkt->setRemotePort(DHCP6_CLIENT_PORT); diff --git a/src/lib/dhcpsrv/dhcp4o6_ipc.cc b/src/lib/dhcpsrv/dhcp4o6_ipc.cc index 031c805956..e3f23fc1f1 100644 --- a/src/lib/dhcpsrv/dhcp4o6_ipc.cc +++ b/src/lib/dhcpsrv/dhcp4o6_ipc.cc @@ -193,21 +193,19 @@ Pkt6Ptr Dhcp4o6IpcBase::receive() { } // Get the option holding source port. - OptionPtr sport = option_vendor->getOption(ISC_V6_4O6_SRC_PORT); - if (!sport || (sport->len() - sport->getHeaderLen() != 2)) { + OptionUint16Ptr sport = boost::dynamic_pointer_cast< + OptionUint16>(option_vendor->getOption(ISC_V6_4O6_SRC_PORT)); + if (!sport) { LOG_WARN(dhcpsrv_logger, DHCPSRV_DHCP4O6_RECEIVED_BAD_PACKET) .arg("no source port suboption"); isc_throw(Dhcp4o6IpcError, "malformed packet (source port suboption missing " - "or has incorrect length)"); + "or has incorrect type)"); } - const OptionBuffer& sport_buf = sport->getData(); - uint16_t sport_value = static_cast(sport_buf[0]) << 8; - sport_value |= static_cast(sport_buf[1]); // Update the packet. pkt->setRemoteAddr(srcs->readAddress()); - pkt->setRemotePort(sport_value); + pkt->setRemotePort(sport->getValue()); pkt->setIface(iface->getName()); pkt->setIndex(iface->getIndex());