45 m_whitelist = std::set<std::string>{
"*"};
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);
104 parseList(m_whitelist, list,
"whitelist");
110 parseList(m_blacklist, list,
"blacklist");
115 std::initializer_list<std::pair<std::string, std::string>> blacklist)
117 parseList(m_whitelist, whitelist);
118 parseList(m_blacklist, 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") {
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"));
168 return this->m_whitelist == other.m_whitelist &&
169 this->m_blacklist == other.m_blacklist;
177 return ::fnmatch(pattern.data(), ifname.data(), 0) == 0;
184 if (rule.find(
'/') != std::string::npos) {
193 return rule ==
"*" ||
201 return std::any_of(m_whitelist.begin(), m_whitelist.end(),
203 std::none_of(m_blacklist.begin(), m_blacklist.end(),
211 if (rule.find(
'/') != std::string::npos) {
224 return std::any_of(m_whitelist.begin(), m_whitelist.end(),
226 std::none_of(m_blacklist.begin(), m_blacklist.end(),
bool operator()(const boost::asio::ip::address &address) const
static Address fromString(const std::string &str)
Creates an Address from a string containing an Ethernet address in hexadecimal notation, with colons or hyphens as separators.
std::string getName() const
Returns the name of the interface, unique on the system.
bool isNull() const
True if this is a null address (00:00:00:00:00:00)
static bool doesNetifMatchRule(const ndn::net::NetworkInterface &netif, const std::string &rule)
std::string toString(char sep=':') const
Converts the address to a human-readable string.
virtual ~NetworkPredicateBase()
static bool doesAddressMatchRule(const boost::asio::ip::address &address, const std::string &rule)
Represents one network interface attached to the host.
static bool doesMatchPattern(const std::string &ifname, const std::string &pattern)
Copyright (c) 2011-2015 Regents of the University of California.
void clear()
Set the whitelist to "*" and clear the blacklist.
static bool isValidCidr(const std::string &cidr)
void assign(std::initializer_list< std::pair< std::string, std::string >> whitelist, std::initializer_list< std::pair< std::string, std::string >> blacklist)
void parseBlacklist(const boost::property_tree::ptree &list)
bool operator==(const NetworkPredicateBase &other) const
void parseWhitelist(const boost::property_tree::ptree &list)
ethernet::Address getEthernetAddress() const
Returns the link-layer (Ethernet) address of the interface.
bool doesContain(const boost::asio::ip::address &address) const
const std::set< NetworkAddress > & getNetworkAddresses() const
Returns a list of all network-layer addresses present on the interface.
bool operator()(const ndn::net::NetworkInterface &netif) const