From: Andrei Pavel Date: Wed, 6 Mar 2024 16:24:37 +0000 (+0200) Subject: [#3262] on completion callback for subnet select X-Git-Tag: Kea-2.5.7~75 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=d20d640e2ca0c5ba135a6e558ad230f3fe946663;p=thirdparty%2Fkea.git [#3262] on completion callback for subnet select --- diff --git a/src/bin/dhcp4/dhcp4_lexer.ll b/src/bin/dhcp4/dhcp4_lexer.ll index d4799108f6..30db220e0e 100644 --- a/src/bin/dhcp4/dhcp4_lexer.ll +++ b/src/bin/dhcp4/dhcp4_lexer.ll @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2023 Internet Systems Consortium, Inc. ("ISC") +/* Copyright (C) 2016-2024 Internet Systems Consortium, Inc. ("ISC") This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 80bba69d43..4f4279a9c1 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -744,7 +744,8 @@ Dhcpv4Srv::selectSubnet(const Pkt4Ptr& query, bool& drop, // reset when this object goes out of scope. All hook points must do // it to prevent possible circular dependency between the callout // handle and its arguments. - ScopedCalloutHandleState callout_handle_state(callout_handle); + shared_ptr callout_handle_state( + std::make_shared(callout_handle)); // Enable copying options from the packet within hook library. ScopedEnableOptionsCopy query4_options_copy(query); @@ -757,13 +758,21 @@ Dhcpv4Srv::selectSubnet(const Pkt4Ptr& query, bool& drop, getCfgSubnets4()->getAll()); // We proactively park the packet. - // Not MT compatible because the unparking callback can be called - // before the current thread exists from this block. - HooksManager::park("subnet4_select", query, - [this, query, allow_answer_park] () { - processLocalizedQuery4AndSendResponse(query, - allow_answer_park); - }); + HooksManager::park( + "subnet4_select", query, [this, query, allow_answer_park, callout_handle_state]() { + if (MultiThreadingMgr::instance().getMode()) { + boost::shared_ptr> callback( + boost::make_shared>( + [this, query, allow_answer_park]() mutable { + processLocalizedQuery4AndSendResponse(query, allow_answer_park); + })); + callout_handle_state->on_completion_ = [callback]() { + MultiThreadingMgr::instance().getThreadPool().add(callback); + }; + } else { + processLocalizedQuery4AndSendResponse(query, allow_answer_park); + } + }); // Call user (and server-side) callouts try { @@ -891,7 +900,8 @@ Dhcpv4Srv::selectSubnet4o6(const Pkt4Ptr& query, bool& drop, // reset when this object goes out of scope. All hook points must do // it to prevent possible circular dependency between the callout // handle and its arguments. - ScopedCalloutHandleState callout_handle_state(callout_handle); + shared_ptr callout_handle_state( + std::make_shared(callout_handle)); // Enable copying options from the packet within hook library. ScopedEnableOptionsCopy query4_options_copy(query); @@ -904,13 +914,21 @@ Dhcpv4Srv::selectSubnet4o6(const Pkt4Ptr& query, bool& drop, getCfgSubnets4()->getAll()); // We proactively park the packet. - // Not MT compatible because the unparking callback can be called - // before the current thread exists from this block. - HooksManager::park("subnet4_select", query, - [this, query, allow_answer_park] () { - processLocalizedQuery4AndSendResponse(query, - allow_answer_park); - }); + HooksManager::park( + "subnet4_select", query, [this, query, allow_answer_park, callout_handle_state]() { + if (MultiThreadingMgr::instance().getMode()) { + boost::shared_ptr> callback( + boost::make_shared>( + [this, query, allow_answer_park]() mutable { + processLocalizedQuery4AndSendResponse(query, allow_answer_park); + })); + callout_handle_state->on_completion_ = [callback]() { + MultiThreadingMgr::instance().getThreadPool().add(callback); + }; + } else { + processLocalizedQuery4AndSendResponse(query, allow_answer_park); + } + }); // Call user (and server-side) callouts try { diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index b4db600e5e..574e6b0442 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -993,6 +993,7 @@ Dhcpv6Srv::processDhcp6Query(Pkt6Ptr query) { return (processLocalizedQuery6(ctx)); } + void Dhcpv6Srv::processLocalizedQuery6AndSendResponse(Pkt6Ptr query, AllocEngine::ClientContext6& ctx) { @@ -2005,7 +2006,8 @@ Dhcpv6Srv::selectSubnet(const Pkt6Ptr& question, bool& drop) { // reset when this object goes out of scope. All hook points must do // it to prevent possible circular dependency between the callout // handle and its arguments. - ScopedCalloutHandleState callout_handle_state(callout_handle); + shared_ptr callout_handle_state( + std::make_shared(callout_handle)); // Enable copying options from the packet within hook library. ScopedEnableOptionsCopy query6_options_copy(question); @@ -2024,10 +2026,19 @@ Dhcpv6Srv::selectSubnet(const Pkt6Ptr& question, bool& drop) { // We proactively park the packet. // Not MT compatible because the unparking callback can be called // before the current thread exists from this block. - HooksManager::park("subnet6_select", question, - [this, question] () { - processLocalizedQuery6AndSendResponse(question); - }); + HooksManager::park("subnet6_select", question, [this, question, callout_handle_state]() { + if (MultiThreadingMgr::instance().getMode()) { + boost::shared_ptr> callback( + boost::make_shared>([this, question]() mutable { + processLocalizedQuery6AndSendResponse(question); + })); + callout_handle_state->on_completion_ = [callback]() { + MultiThreadingMgr::instance().getThreadPool().add(callback); + }; + } else { + processLocalizedQuery6AndSendResponse(question); + } + }); // Call user (and server-side) callouts try {