diff options
author | Tom Gundersen <teg@jklm.no> | 2014-02-25 21:16:17 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-02-25 21:19:08 +0100 |
commit | fe6b2d55bcb379d01664ed28cea40634cb6b52e3 (patch) | |
tree | 330da49ab0f895c7c1618a36b4439f41a04d9472 /src/network/networkd-network.c | |
parent | e3ab0c0e19227efdf15237dd9136fc6fc7f3839d (diff) |
networkd: add basic support for MACVLANs
Diffstat (limited to 'src/network/networkd-network.c')
-rw-r--r-- | src/network/networkd-network.c | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 14fa92aeaf..ca79d4ff6d 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -53,10 +53,14 @@ static int network_load_one(Manager *manager, const char *filename) { LIST_HEAD_INIT(network->static_addresses); LIST_HEAD_INIT(network->static_routes); - network->vlans = hashmap_new(uint64_hash_func, uint64_compare_func); + network->vlans = hashmap_new(string_hash_func, string_compare_func); if (!network->vlans) return log_oom(); + network->macvlans = hashmap_new(uint64_hash_func, uint64_compare_func); + if (!network->macvlans) + return log_oom(); + network->addresses_by_section = hashmap_new(uint64_hash_func, uint64_compare_func); if (!network->addresses_by_section) return log_oom(); @@ -150,6 +154,8 @@ void network_free(Network *network) { hashmap_free(network->vlans); + hashmap_free(network->macvlans); + while ((route = network->static_routes)) route_free(route); @@ -330,3 +336,45 @@ int config_parse_vlan(const char *unit, return 0; } + +int config_parse_macvlan(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) { + Network *network = userdata; + NetDev *netdev; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + r = netdev_get(network->manager, rvalue, &netdev); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, EINVAL, + "MACVLAN is invalid, ignoring assignment: %s", rvalue); + return 0; + } + + if (netdev->kind != NETDEV_KIND_MACVLAN) { + log_syntax(unit, LOG_ERR, filename, line, EINVAL, + "NetDev is not a MACVLAN, ignoring assignment: %s", rvalue); + return 0; + } + + r = hashmap_put(network->macvlans, netdev->name, netdev); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, EINVAL, + "Can not add MACVLAN to network: %s", rvalue); + return 0; + } + + return 0; +} |