50 NetworkPredicateBase::parseList(std::set<std::string>&
set,
51 const boost::property_tree::ptree& list,
52 const std::string& section)
56 for (
const auto& item : list) {
57 if (item.first ==
"*") {
59 set.insert(item.first);
62 if (!isRuleSupported(item.first)) {
64 "' in section '" + section +
"'"));
67 auto value = item.second.get_value<std::string>();
68 if (!isRuleValid(item.first, value)) {
70 "' in section '" + section +
"'"));
78 NetworkPredicateBase::parseList(std::set<std::string>&
set,
79 std::initializer_list<std::pair<std::string, std::string>> list)
83 for (
const auto& item : list) {
84 if (item.first ==
"*") {
86 set.insert(item.first);
89 if (!isRuleSupported(item.first)) {
90 NDN_THROW(std::runtime_error(
"Unrecognized rule '" + item.first +
"'"));
93 if (!isRuleValid(item.first, item.second)) {
94 NDN_THROW(std::runtime_error(
"Malformed " + item.first +
" '" + item.second +
"'"));
96 set.insert(item.second);
115 std::initializer_list<std::pair<std::string, std::string>> blacklist)
122 NetworkInterfacePredicate::isRuleSupported(
const std::string& key)
124 return key ==
"ifname" || key ==
"ether" || key ==
"subnet";
128 NetworkInterfacePredicate::isRuleValid(
const std::string& key,
const std::string& value)
130 if (key ==
"ifname") {
132 return !value.empty();
134 else if (key ==
"ether") {
136 return !ndn::ethernet::Address::fromString(value).isNull();
138 else if (key ==
"subnet") {
143 NDN_THROW(std::logic_error(
"Only supported rules are expected"));
148 IpAddressPredicate::isRuleSupported(
const std::string& key)
150 return key ==
"subnet";
154 IpAddressPredicate::isRuleValid(
const std::string& key,
const std::string& value)
156 if (key ==
"subnet") {
161 NDN_THROW(std::logic_error(
"Only supported rules are expected"));
177 return ::fnmatch(pattern.data(), ifname.data(), 0) == 0;
184 if (rule.find(
'/') != std::string::npos) {
186 for (
const auto& addr : netif.getNetworkAddresses()) {
193 return rule ==
"*" ||
195 netif.getEthernetAddress().toString() == rule;
209 if (rule.find(
'/') != std::string::npos) {
void parseWhitelist(const boost::property_tree::ptree &list)
void parseBlacklist(const boost::property_tree::ptree &list)
bool operator==(const NetworkPredicateBase &other) const
static bool doesNetifMatchRule(const ndn::net::NetworkInterface &netif, const std::string &rule)
std::set< std::string > m_blacklist
std::set< std::string > m_whitelist
static bool doesAddressMatchRule(const boost::asio::ip::address &address, const std::string &rule)
static bool isValidCidr(const std::string &cidr)
static bool doesMatchPattern(const std::string &ifname, const std::string &pattern)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
bool operator()(const ndn::net::NetworkInterface &netif) const
virtual ~NetworkPredicateBase()
bool doesContain(const boost::asio::ip::address &address) const
void clear()
Set the whitelist to "*" and clear the blacklist.
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 boost::asio::ip::address &address) const