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") {
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) {
180 Network n = boost::lexical_cast<Network>(rule);
188 return rule ==
"*" ||
204 if (rule.find(
'/') != std::string::npos) {
205 Network n = boost::lexical_cast<Network>(rule);
static Address fromString(const std::string &str)
Creates an Address from a string containing an Ethernet address in hexadecimal notation,...
void assign(std::initializer_list< std::pair< std::string, std::string >> whitelist, std::initializer_list< std::pair< std::string, std::string >> blacklist)
static bool doesNetifMatchRule(const ndn::net::NetworkInterface &netif, const std::string &rule)
virtual ~NetworkPredicateBase()
bool operator()(const boost::asio::ip::address &address) const
std::string getName() const
Returns the name of the interface, unique on the system.
void parseWhitelist(const boost::property_tree::ptree &list)
bool isNull() const
True if this is a null address (00:00:00:00:00:00)
std::string toString(char sep=':') const
Converts the address to a human-readable string.
static bool doesMatchPattern(const std::string &ifname, const std::string &pattern)
std::set< std::string > m_whitelist
Represents one network interface attached to the host.
void parseBlacklist(const boost::property_tree::ptree &list)
Copyright (c) 2011-2015 Regents of the University of California.
bool operator==(const NetworkPredicateBase &other) const
static bool isValidCidr(const std::string &cidr)
bool operator()(const ndn::net::NetworkInterface &netif) const
void clear()
Set the whitelist to "*" and clear the blacklist.
ethernet::Address getEthernetAddress() const
Returns the link-layer (Ethernet) address of the interface.
std::set< std::string > m_blacklist
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.
static bool doesAddressMatchRule(const boost::asio::ip::address &address, const std::string &rule)