26 #include <boost/algorithm/string/predicate.hpp>
41 m_filters.push_back(std::move(filter));
47 m_checkers.push_back(std::move(checker));
51 Rule::match(uint32_t pktType,
const Name& pktName,
const shared_ptr<ValidationState>& state)
const
54 if (pktType != m_pktType) {
59 if (m_filters.empty()) {
64 for (
const auto& filter : m_filters) {
65 retval |= filter->match(pktType, pktName, state);
75 const shared_ptr<ValidationState>& state)
const
77 NDN_LOG_TRACE(
"Trying to check " << pktName <<
" with KeyLocator " << klName);
79 if (pktType != m_pktType) {
84 std::vector<Checker::Result> checkerResults;
85 checkerResults.reserve(m_checkers.size());
86 for (
const auto& checker : m_checkers) {
87 auto result = checker->check(pktType, sigType, pktName, klName, *state);
91 checkerResults.push_back(std::move(result));
94 std::ostringstream err;
95 err <<
"Packet " << pktName <<
" (KeyLocator=" << klName <<
") cannot pass any checker.";
96 for (
size_t i = 0; i < checkerResults.size(); ++i) {
97 err <<
"\nChecker " << i <<
": " << checkerResults[i].getErrorMessage();
106 auto propertyIt = configSection.begin();
109 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"id")) {
113 std::string ruleId = propertyIt->second.data();
117 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"for")) {
121 std::string usage = propertyIt->second.data();
124 bool isForData =
false;
125 if (boost::iequals(usage,
"data")) {
128 else if (boost::iequals(usage,
"interest")) {
132 NDN_THROW(
Error(
"Unrecognized <rule.for>: " + usage +
" in rule: " + ruleId));
138 for (; propertyIt != configSection.end(); propertyIt++) {
139 if (!boost::iequals(propertyIt->first,
"filter")) {
140 if (boost::iequals(propertyIt->first,
"checker")) {
146 rule->addFilter(
Filter::create(propertyIt->second, configFilename));
150 bool hasCheckers =
false;
151 for (; propertyIt != configSection.end(); propertyIt++) {
152 if (!boost::iequals(propertyIt->first,
"checker")) {
160 if (propertyIt != configSection.end()) {
165 NDN_THROW(
Error(
"No <rule.checker> is specified in rule: " + ruleId));
Represents an absolute name.
@ POLICY_ERROR
The packet violates the validation rules enforced by the policy.
static unique_ptr< Checker > create(const ConfigSection &configSection, const std::string &configFilename)
Create a checker from configuration section.
static unique_ptr< Filter > create(const ConfigSection &configSection, const std::string &configFilename)
Create a filter from the configuration section.
void addFilter(unique_ptr< Filter > filter)
bool check(uint32_t pktType, tlv::SignatureTypeValue sigType, const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state) const
Check if packet satisfies rule's condition.
static unique_ptr< Rule > create(const ConfigSection &configSection, const std::string &configFilename)
Create a rule from configuration section.
Rule(const std::string &id, uint32_t pktType)
void addChecker(unique_ptr< Checker > checker)
bool match(uint32_t pktType, const Name &pktName, const shared_ptr< ValidationState > &state) const
Check if the packet name matches rule's filter.
#define NDN_LOG_TRACE(expression)
Log at TRACE level.
#define NDN_LOG_INIT(name)
Define a non-member log module.
std::string to_string(const errinfo_stacktrace &x)
boost::property_tree::ptree ConfigSection
Contains the ndn-cxx security framework.
SignatureTypeValue
SignatureType values.