summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-network-gperf.gperf8
-rw-r--r--src/network/networkd-network.c157
-rw-r--r--src/network/networkd.h14
3 files changed, 47 insertions, 132 deletions
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index 6ba890ff9b..bfe44e0041 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -25,10 +25,10 @@ Match.Virtualization, config_parse_net_condition, CONDITION_VIRTU
Match.KernelCommandLine, config_parse_net_condition, CONDITION_KERNEL_COMMAND_LINE, offsetof(Network, match_kernel)
Match.Architecture, config_parse_net_condition, CONDITION_ARCHITECTURE, offsetof(Network, match_arch)
Network.Description, config_parse_string, 0, offsetof(Network, description)
-Network.Bridge, config_parse_bridge, 0, offsetof(Network, bridge)
-Network.Bond, config_parse_bond, 0, offsetof(Network, bond)
-Network.VLAN, config_parse_vlan, 0, offsetof(Network, vlans)
-Network.MACVLAN, config_parse_macvlan, 0, offsetof(Network, macvlans)
+Network.Bridge, config_parse_netdev, 0, offsetof(Network, bridge)
+Network.Bond, config_parse_netdev, 0, offsetof(Network, bond)
+Network.VLAN, config_parse_netdev, 0, offsetof(Network, vlans)
+Network.MACVLAN, config_parse_netdev, 0, offsetof(Network, macvlans)
Network.DHCP, config_parse_bool, 0, offsetof(Network, dhcp)
Network.IPv4LL, config_parse_bool, 0, offsetof(Network, ipv4ll)
Network.Address, config_parse_address, 0, 0
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 4d01e55fee..4493359d79 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -19,6 +19,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include <ctype.h>
+
#include "networkd.h"
#include "network-internal.h"
#include "path-util.h"
@@ -235,7 +237,7 @@ int network_apply(Manager *manager, Network *network, Link *link) {
return 0;
}
-int config_parse_bridge(const char *unit,
+int config_parse_netdev(const char *unit,
const char *filename,
unsigned line,
const char *section,
@@ -246,7 +248,9 @@ int config_parse_bridge(const char *unit,
void *data,
void *userdata) {
Network *network = userdata;
+ char *kind_string, *p;
NetDev *netdev;
+ NetDevKind kind;
int r;
assert(filename);
@@ -254,140 +258,63 @@ int config_parse_bridge(const char *unit,
assert(rvalue);
assert(data);
- r = netdev_get(network->manager, rvalue, &netdev);
- if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Bridge is invalid, ignoring assignment: %s", rvalue);
- return 0;
- }
-
- if (netdev->kind != NETDEV_KIND_BRIDGE) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "NetDev is not a bridge, ignoring assignment: %s", rvalue);
- return 0;
- }
-
- network->bridge = netdev;
-
- return 0;
-}
-
-int config_parse_bond(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);
+ kind_string = strdup(lvalue);
+ if (!kind_string)
+ return log_oom();
- r = netdev_get(network->manager, rvalue, &netdev);
- if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Bond is invalid, ignoring assignment: %s", rvalue);
- return 0;
- }
+ /* the keys are CamelCase versions of the kind */
+ for (p = kind_string; *p; p++)
+ *p = tolower(*p);
- if (netdev->kind != NETDEV_KIND_BOND) {
+ kind = netdev_kind_from_string(kind_string);
+ if (kind == _NETDEV_KIND_INVALID) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "NetDev is not a bond, ignoring assignment: %s", rvalue);
+ "Invalid NetDev kind: %s", lvalue);
return 0;
}
- network->bond = netdev;
-
- return 0;
-}
-
-int config_parse_vlan(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,
- "VLAN is invalid, ignoring assignment: %s", rvalue);
+ "%s could not be found, ignoring assignment: %s", lvalue, rvalue);
return 0;
}
- if (netdev->kind != NETDEV_KIND_VLAN) {
+ if (netdev->kind != kind) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "NetDev is not a VLAN, ignoring assignment: %s", rvalue);
+ "NetDev is not a %s, ignoring assignment: %s", lvalue, rvalue);
return 0;
}
- r = hashmap_put(network->vlans, &netdev->vlanid, netdev);
- if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Can not add VLAN to network: %s", rvalue);
- return 0;
- }
+ switch (kind) {
+ case NETDEV_KIND_BRIDGE:
+ network->bridge = netdev;
- return 0;
-}
+ break;
+ case NETDEV_KIND_BOND:
+ network->bond = netdev;
-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;
- }
+ break;
+ case NETDEV_KIND_VLAN:
+ r = hashmap_put(network->vlans, &netdev->vlanid, netdev);
+ if (r < 0) {
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+ "Can not add VLAN to network: %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;
- }
+ break;
+ case NETDEV_KIND_MACVLAN:
+ 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;
+ }
- 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;
+ break;
+ default:
+ assert_not_reached("Can not parse NetDev");
}
return 0;
diff --git a/src/network/networkd.h b/src/network/networkd.h
index b2794bad2d..cff0136bcc 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -309,22 +309,10 @@ int network_get(Manager *manager, struct udev_device *device,
Network **ret);
int network_apply(Manager *manager, Network *network, Link *link);
-int config_parse_bridge(const char *unit, const char *filename, unsigned line,
+int config_parse_netdev(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);
-int config_parse_bond(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);
-
-int config_parse_vlan(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);
-
-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);
-
/* gperf */
const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, unsigned length);