From: FredericDT Date: Wed, 31 Aug 2022 08:02:19 +0000 (+0800) Subject: Drop setLocalBindAddress bool parameter, pass X-Git-Tag: rec-4.8.0-alpha1~36^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8dbb2c9b9da9d4cb1864158f79f59cd2f50efa89;p=thirdparty%2Fpdns.git Drop setLocalBindAddress bool parameter, pass boost::optional instead. According to https://github.com/PowerDNS/pdns/pull/11889 > An extra boolean flag is no needed for boost::optional Thanks Moerbeek and Gacogne Signed-off-by: FredericDT --- diff --git a/pdns/dnsdist-lua-actions.cc b/pdns/dnsdist-lua-actions.cc index ea9ccbc0a4..637e5fc109 100644 --- a/pdns/dnsdist-lua-actions.cc +++ b/pdns/dnsdist-lua-actions.cc @@ -127,7 +127,7 @@ class TeeAction : public DNSAction { public: // this action does not stop the processing - TeeAction(const ComboAddress& rca, const ComboAddress& lca, bool setLocalBindAddress=false, bool addECS=false); + TeeAction(const ComboAddress& rca, const boost::optional& lca, bool addECS=false); ~TeeAction() override; DNSAction::Action operator()(DNSQuestion* dq, std::string* ruleresult) const override; std::string toString() const override; @@ -135,7 +135,7 @@ public: private: ComboAddress d_remote; - ComboAddress d_local; + boost::optional d_local; std::thread d_worker; void worker(); @@ -153,17 +153,16 @@ private: mutable stat_t d_tcpdrops{0}; stat_t d_otherrcode{0}; std::atomic d_pleaseQuit{false}; - bool d_setLocalBindAddress{false}; bool d_addECS{false}; }; -TeeAction::TeeAction(const ComboAddress& rca, const ComboAddress& lca, bool setLocalBindAddress, bool addECS) - : d_remote(rca), d_local(lca), d_setLocalBindAddress(setLocalBindAddress), d_addECS(addECS) +TeeAction::TeeAction(const ComboAddress& rca, const boost::optional& lca, bool addECS) + : d_remote(rca), d_local(lca), d_addECS(addECS) { d_fd=SSocket(d_remote.sin4.sin_family, SOCK_DGRAM, 0); try { - if (d_setLocalBindAddress) { - SBind(d_fd, d_local); + if (d_local) { + SBind(d_fd, *d_local); } SConnect(d_fd, d_remote); setNonBlocking(d_fd); @@ -2423,7 +2422,12 @@ void setupLuaActions(LuaContext& luaCtx) #endif /* DISABLE_PROTOBUF */ luaCtx.writeFunction("TeeAction", [](const std::string& remote, boost::optional addECS, boost::optional local) { - return std::shared_ptr(new TeeAction(ComboAddress(remote, 53), ComboAddress(local ? *local : "0.0.0.0", 0), local ? true : false, addECS ? *addECS : false)); + boost::optional localAddr{boost::none}; + if (local) { + localAddr = ComboAddress(*local, 0); + } + + return std::shared_ptr(new TeeAction(ComboAddress(remote, 53), localAddr, addECS ? *addECS : false)); }); luaCtx.writeFunction("SetECSPrefixLengthAction", [](uint16_t v4PrefixLength, uint16_t v6PrefixLength) {