From: Francis Dupont Date: Sat, 9 May 2020 12:44:22 +0000 (+0200) Subject: [#1147] Split processPacket X-Git-Tag: Kea-1.7.9~139 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25208e91c4d071409e844204bcf0833d0dcbd5e0;p=thirdparty%2Fkea.git [#1147] Split processPacket --- diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index cac51e8bf9..e33e7de9cb 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -1238,6 +1238,31 @@ Dhcpv4Srv::processPacket(Pkt4Ptr& query, Pkt4Ptr& rsp, bool allow_packet_park) { } } + processDhcp4Query(query, rsp, allow_packet_park); +} + +void +Dhcpv4Srv::processDhcp4QueryAndSendResponse(Pkt4Ptr& query, Pkt4Ptr& rsp, + bool allow_packet_park) { + try { + processDhcp4Query(query, rsp, allow_packet_park); + if (!rsp) { + return; + } + + CalloutHandlePtr callout_handle = getCalloutHandle(query); + processPacketBufferSend(callout_handle, rsp); + } catch (const std::exception& e) { + LOG_ERROR(packet4_logger, DHCP4_PACKET_PROCESS_STD_EXCEPTION) + .arg(e.what()); + } catch (...) { + LOG_ERROR(packet4_logger, DHCP4_PACKET_PROCESS_EXCEPTION); + } +} + +void +Dhcpv4Srv::processDhcp4Query(Pkt4Ptr& query, Pkt4Ptr& rsp, + bool allow_packet_park) { AllocEngine::ClientContext4Ptr ctx; try { diff --git a/src/bin/dhcp4/dhcp4_srv.h b/src/bin/dhcp4/dhcp4_srv.h index b8ae778757..fdddf9746a 100644 --- a/src/bin/dhcp4/dhcp4_srv.h +++ b/src/bin/dhcp4/dhcp4_srv.h @@ -327,7 +327,7 @@ public: /// @brief Process a single incoming DHCPv4 packet and sends the response. /// - /// It verifies correctness of the passed packet, call per-type processXXX + /// It verifies correctness of the passed packet, calls per-type processXXX /// methods, generates appropriate answer, sends the answer to the client. /// /// @param query A pointer to the packet to be processed. @@ -335,7 +335,7 @@ public: /// @brief Process a single incoming DHCPv4 packet and sends the response. /// - /// It verifies correctness of the passed packet, call per-type processXXX + /// It verifies correctness of the passed packet, calls per-type processXXX /// methods, generates appropriate answer, sends the answer to the client. /// /// @param query A pointer to the packet to be processed. @@ -345,21 +345,42 @@ public: /// /// @param callout_handle pointer to the callout handle. /// @param query A pointer to the packet to be processed. - /// @param rsp A pointer to the response + /// @param rsp A pointer to the response. void sendResponseNoThrow(hooks::CalloutHandlePtr& callout_handle, Pkt4Ptr& query, Pkt4Ptr& rsp); /// @brief Process a single incoming DHCPv4 packet. /// - /// It verifies correctness of the passed packet, call per-type processXXX + /// It verifies correctness of the passed packet, calls per-type processXXX /// methods, generates appropriate answer. /// /// @param query A pointer to the packet to be processed. - /// @param rsp A pointer to the response + /// @param rsp A pointer to the response. /// @param allow_packet_park Indicates if parking a packet is allowed. void processPacket(Pkt4Ptr& query, Pkt4Ptr& rsp, bool allow_packet_park = true); + /// @brief Process a single incoming DHCPv4 query. + /// + /// It calls per-type processXXX methods, generates appropriate answer. + /// + /// @param query A pointer to the packet to be processed. + /// @param rsp A pointer to the response. + /// @param allow_packet_park Indicates if parking a packet is allowed. + void processDhcp4Query(Pkt4Ptr& query, Pkt4Ptr& rsp, + bool allow_packet_park); + + /// @brief Process a single incoming DHCPv4 query. + /// + /// It calls per-type processXXX methods, generates appropriate answer, + /// sends the answer to the client. + /// + /// @param query A pointer to the packet to be processed. + /// @param rsp A pointer to the response. + /// @param allow_packet_park Indicates if parking a packet is allowed. + void processDhcp4QueryAndSendResponse(Pkt4Ptr& query, Pkt4Ptr& rsp, + bool allow_packet_park); + /// @brief Instructs the server to shut down. void shutdown(); diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index 6338288c93..cf673b0e8e 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -816,6 +816,29 @@ Dhcpv6Srv::processPacket(Pkt6Ptr& query, Pkt6Ptr& rsp) { return; } + processDhcp6Query(query, rsp); +} + +void +Dhcpv6Srv::processDhcp6QueryAndSendResponse(Pkt6Ptr& query, Pkt6Ptr& rsp) { + try { + processDhcp6Query(query, rsp); + if (!rsp) { + return; + } + + CalloutHandlePtr callout_handle = getCalloutHandle(query); + processPacketBufferSend(callout_handle, rsp); + } catch (const std::exception& e) { + LOG_ERROR(packet6_logger, DHCP6_PACKET_PROCESS_STD_EXCEPTION) + .arg(e.what()); + } catch (...) { + LOG_ERROR(packet6_logger, DHCP6_PACKET_PROCESS_EXCEPTION); + } +} + +void +Dhcpv6Srv::processDhcp6Query(Pkt6Ptr& query, Pkt6Ptr& rsp) { // Create a client race avoidance RAII handler. ClientHandler client_handler; bool drop = false; diff --git a/src/bin/dhcp6/dhcp6_srv.h b/src/bin/dhcp6/dhcp6_srv.h index a7de75fae8..6845921bbc 100644 --- a/src/bin/dhcp6/dhcp6_srv.h +++ b/src/bin/dhcp6/dhcp6_srv.h @@ -151,7 +151,7 @@ public: /// @brief Process a single incoming DHCPv6 packet and sends the response. /// - /// It verifies correctness of the passed packet, call per-type processXXX + /// It verifies correctness of the passed packet, calls per-type processXXX /// methods, generates appropriate answer, sends the answer to the client. /// /// @param query A pointer to the packet to be processed. @@ -159,7 +159,7 @@ public: /// @brief Process a single incoming DHCPv6 packet and sends the response. /// - /// It verifies correctness of the passed packet, call per-type processXXX + /// It verifies correctness of the passed packet, calls per-type processXXX /// methods, generates appropriate answer, sends the answer to the client. /// /// @param query A pointer to the packet to be processed. @@ -169,19 +169,36 @@ public: /// /// @param callout_handle pointer to the callout handle. /// @param query A pointer to the packet to be processed. - /// @param rsp A pointer to the response + /// @param rsp A pointer to the response. void sendResponseNoThrow(hooks::CalloutHandlePtr& callout_handle, Pkt6Ptr& query, Pkt6Ptr& rsp); /// @brief Process a single incoming DHCPv6 packet. /// - /// It verifies correctness of the passed packet, call per-type processXXX + /// It verifies correctness of the passed packet, calls per-type processXXX /// methods, generates appropriate answer. /// /// @param query A pointer to the packet to be processed. - /// @param rsp A pointer to the response + /// @param rsp A pointer to the response. void processPacket(Pkt6Ptr& query, Pkt6Ptr& rsp); + /// @brief Process a single incoming DHCPv6 query. + /// + /// It calls per-type processXXX methods, generates appropriate answer. + /// + /// @param query A pointer to the packet to be processed. + /// @param rsp A pointer to the response. + void processDhcp6Query(Pkt6Ptr& query, Pkt6Ptr& rsp); + + /// @brief Process a single incoming DHCPv6 query. + /// + /// It calls per-type processXXX methods, generates appropriate answer, + /// sends the answer to the client. + /// + /// @param query A pointer to the packet to be processed. + /// @param rsp A pointer to the response. + void processDhcp6QueryAndSendResponse(Pkt6Ptr& query, Pkt6Ptr& rsp); + /// @brief Instructs the server to shut down. void shutdown();