// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved. // Licensed under the Apache License, Version 2.0 (the "License"); // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "connkey.h" #include "environment/evaluator_templates.h" #include using namespace std; using namespace EnvironmentHelper; class ConstantPort : public Constant { public: ConstantPort(const vector ¶ms) : Constant( [] (const string & str) { uint16_t value = 0; try { value = boost::lexical_cast(str); } catch (boost::bad_lexical_cast const&) { reportWrongParamType(getName(), str, "Not a port number"); } return value; }, params ) {} static string getName() { return Constant::getName() + "Port"; } }; class ConstantIP : public Constant { public: ConstantIP(const vector ¶ms) : Constant( [] (const string & str) { auto addr = IPAddr::createIPAddr(str); if (!addr.ok()) reportWrongParamType(getName(), str, "Not an IP address"); return *addr; }, params ) {} static string getName() { return Constant::getName() + "IP"; } }; class ConstantProtocol : public Constant { public: ConstantProtocol(const vector ¶ms) : Constant( [] (const string &str) { uint16_t value = 0; for (auto &ch : str) { if (ch < '0' || ch > '9') reportWrongParamType(getName(), str, "Not a protocol ID character"); value = value * 10 + (ch - '0'); if (256 <= value) reportWrongParamType(getName(), str, "Not a protocol ID number"); } return static_cast(value); }, params ) {} static string getName() { return Constant::getName() + "Protocol"; } }; class EqualPort : public Equal { public: EqualPort(const vector ¶ms) : Equal(params) {} static string getName() { return Equal::getName() + "Port"; } }; class EqualIP : public Equal { public: EqualIP(const vector ¶ms) : Equal(params) {} static string getName() { return Equal::getName() + "IP"; } }; class EqualProtocol : public Equal { public: EqualProtocol(const vector ¶ms) : Equal(params) {} static string getName() { return Equal::getName() + "Protocol"; } }; class DPort : public Invoker { public: DPort(const vector ¶ms) : Invoker([] (const ConnKey &key) { return key.getDPort(); }, params) {} static string getName() { return Invoker::getName() + "DPort"; } }; class SPort : public Invoker { public: SPort(const vector ¶ms) : Invoker([] (const ConnKey &key) { return key.getSPort(); }, params) {} static string getName() { return Invoker::getName() + "SPort"; } }; class Dst : public Invoker { public: Dst(const vector ¶ms) : Invoker([] (const ConnKey &key) { return key.getDst(); }, params) {} static string getName() { return Invoker::getName() + "Dst"; } }; class Src : public Invoker { public: Src(const vector ¶ms) : Invoker([] (const ConnKey &key) { return key.getSrc(); }, params) {} static string getName() { return Invoker::getName() + "Src"; } }; class Protocol : public Invoker { public: Protocol(const vector ¶ms) : Invoker([] (const ConnKey &key) { return key.getProto(); }, params) {} static string getName() { return Invoker::getName() + "Protocol"; } }; void ConnKey::preload() { addMatcher(); addMatcher(); addMatcher(); addMatcher(); addMatcher(); addMatcher(); addMatcher(); addMatcher(); addMatcher(); addMatcher(); addMatcher(); }