summaryrefslogtreecommitdiff
path: root/src/shared/net-util.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-02-20 19:39:49 +0100
committerTom Gundersen <teg@jklm.no>2014-02-20 21:50:34 +0100
commit2cc412b59353576cece2d5b30c6a39c70552f0a0 (patch)
treedc8257a5b09b0ceca44ddda74d9df20f825e9842 /src/shared/net-util.c
parentb77c08e06b67d5b1dd8aaf67b732e93851d8ae43 (diff)
network/link: Match - filter on kernel cmdline, host and virt
Diffstat (limited to 'src/shared/net-util.c')
-rw-r--r--src/shared/net-util.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/shared/net-util.c b/src/shared/net-util.c
index ba21ae437f..06c50b593e 100644
--- a/src/shared/net-util.c
+++ b/src/shared/net-util.c
@@ -28,18 +28,31 @@
#include "utf8.h"
#include "util.h"
#include "conf-parser.h"
+#include "condition.h"
bool net_match_config(const struct ether_addr *match_mac,
const char *match_path,
const char *match_driver,
const char *match_type,
const char *match_name,
+ Condition *match_host,
+ Condition *match_virt,
+ Condition *match_kernel,
const char *dev_mac,
const char *dev_path,
const char *dev_driver,
const char *dev_type,
const char *dev_name) {
+ if (match_host && !condition_test_host(match_host))
+ return 0;
+
+ if (match_virt && !condition_test_virtualization(match_virt))
+ return 0;
+
+ if (match_kernel && !condition_test_kernel_command_line(match_kernel))
+ return 0;
+
if (match_mac && (!dev_mac || memcmp(match_mac, ether_aton(dev_mac), ETH_ALEN)))
return 0;
@@ -64,6 +77,47 @@ unsigned net_netmask_to_prefixlen(const struct in_addr *addr) {
return 32 - u32ctz(be32toh(addr->s_addr));
}
+int config_parse_net_condition(const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ ConditionType cond = ltype;
+ Condition **ret = data;
+ bool negate;
+ Condition *c;
+ _cleanup_free_ char *s = NULL;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+
+ negate = rvalue[0] == '!';
+ if (negate)
+ rvalue++;
+
+ s = strdup(rvalue);
+ if (!s)
+ return log_oom();
+
+ c = condition_new(cond, s, false, negate);
+ if (!c)
+ return log_oom();
+
+ if (*ret)
+ condition_free(*ret);
+
+ *ret = c;
+ return 0;
+}
+
int config_parse_ifname(const char *unit,
const char *filename,
unsigned line,