50 NetworkPredicateBase::parseList(std::set<std::string>&
set,
const boost::property_tree::ptree& list,
const std::string& section)
54 for (
const auto& item : list) {
55 if (item.first ==
"*") {
57 set.insert(item.first);
60 if (!isRuleSupported(item.first)) {
61 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Unrecognized rule \"" + item.first +
"\" in \"" + section +
"\" section"));
64 auto value = item.second.get_value<std::string>();
65 if (!isRuleValid(item.first, value)) {
66 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Malformed " + item.first +
" \"" + value +
"\" in \"" + section +
"\" section"));
74 NetworkPredicateBase::parseList(std::set<std::string>&
set, std::initializer_list<std::pair<std::string, std::string>> list)
78 for (
const auto& item : list) {
79 if (item.first ==
"*") {
81 set.insert(item.first);
84 if (!isRuleSupported(item.first)) {
85 BOOST_THROW_EXCEPTION(std::runtime_error(
"Unrecognized rule \"" + item.first +
"\""));
88 if (!isRuleValid(item.first, item.second)) {
89 BOOST_THROW_EXCEPTION(std::runtime_error(
"Malformed " + item.first +
" \"" + item.second +
"\""));
91 set.insert(item.second);
110 std::initializer_list<std::pair<std::string, std::string>> blacklist)
117 NetworkInterfacePredicate::isRuleSupported(
const std::string& key)
119 return key ==
"ifname" || key ==
"ether" || key ==
"subnet";
123 NetworkInterfacePredicate::isRuleValid(
const std::string& key,
const std::string& value)
125 if (key ==
"ifname") {
127 return !value.empty();
129 else if (key ==
"ether") {
131 return !ndn::ethernet::Address::fromString(value).isNull();
133 else if (key ==
"subnet") {
138 BOOST_THROW_EXCEPTION(std::logic_error(
"Only supported rules are expected"));
143 IpAddressPredicate::isRuleSupported(
const std::string& key)
145 return key ==
"subnet";
149 IpAddressPredicate::isRuleValid(
const std::string& key,
const std::string& value)
151 if (key ==
"subnet") {
156 BOOST_THROW_EXCEPTION(std::logic_error(
"Only supported rules are expected"));
172 return ::fnmatch(pattern.data(), ifname.data(), 0) == 0;
179 if (rule.find(
'/') != std::string::npos) {
181 for (
const auto& addr : netif.getNetworkAddresses()) {
188 return rule ==
"*" ||
190 netif.getEthernetAddress().toString() == rule;
204 if (rule.find(
'/') != std::string::npos) {
void parseWhitelist(const boost::property_tree::ptree &list)
std::set< std::string > m_blacklist
static bool doesNetifMatchRule(const ndn::net::NetworkInterface &netif, const std::string &rule)
bool operator()(const boost::asio::ip::address &address) const
virtual ~NetworkPredicateBase()
static bool doesMatchPattern(const std::string &ifname, const std::string &pattern)
bool operator==(const NetworkPredicateBase &other) const
static bool isValidCidr(const std::string &cidr)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
void assign(std::initializer_list< std::pair< std::string, std::string >> whitelist, std::initializer_list< std::pair< std::string, std::string >> blacklist)
bool operator()(const ndn::net::NetworkInterface &netif) const
void parseBlacklist(const boost::property_tree::ptree &list)
bool doesContain(const boost::asio::ip::address &address) const
void clear()
Set the whitelist to "*" and clear the blacklist.
std::set< std::string > m_whitelist
static bool doesAddressMatchRule(const boost::asio::ip::address &address, const std::string &rule)