summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-03-26 19:25:01 +0100
committerTom Gundersen <teg@jklm.no>2014-03-28 19:11:59 +0100
commitd8e538ecd9e62f841242f07e3df5c835c1ba6313 (patch)
tree0fba56485f73d01a985ed4afaff83cffa19068d2 /src/network
parent9f5bbfe354c52cd9e28cca32c35596b73e8d738b (diff)
sd-rtnl: rework rtnl type system
Use a static table with all the typing information, rather than repeated switch statements. This should make it a lot simpler to add new types. We need to keep all the type info to be able to create containers without exposing their implementation details to the users of the library. As a freebee we verify the types of appended/read attributes. The API is extended to nicely deal with unions of container types.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkd-netdev.c52
1 files changed, 21 insertions, 31 deletions
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index e333c47b1f..15a5d7cdff 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -291,48 +291,30 @@ static int netdev_create(NetDev *netdev, Link *link, sd_rtnl_message_handler_t c
return -EINVAL;
}
- r = sd_rtnl_message_append_string(req, IFLA_INFO_KIND, kind);
+ r = sd_rtnl_message_open_container_union(req, IFLA_INFO_DATA, kind);
if (r < 0) {
log_error_netdev(netdev,
- "Could not append IFLA_INFO_KIND attribute: %s",
- strerror(-r));
+ "Could not open IFLA_INFO_DATA container: %s",
+ strerror(-r));
return r;
}
- if (netdev->vlanid <= VLANID_MAX || netdev->macvlan_mode != _NETDEV_MACVLAN_MODE_INVALID) {
- r = sd_rtnl_message_open_container(req, IFLA_INFO_DATA);
+ if (netdev->vlanid <= VLANID_MAX) {
+ r = sd_rtnl_message_append_u16(req, IFLA_VLAN_ID, netdev->vlanid);
if (r < 0) {
log_error_netdev(netdev,
- "Could not open IFLA_INFO_DATA container: %s",
+ "Could not append IFLA_VLAN_ID attribute: %s",
strerror(-r));
return r;
}
+ }
- if (netdev->vlanid <= VLANID_MAX) {
- r = sd_rtnl_message_append_u16(req, IFLA_VLAN_ID, netdev->vlanid);
- if (r < 0) {
- log_error_netdev(netdev,
- "Could not append IFLA_VLAN_ID attribute: %s",
- strerror(-r));
- return r;
- }
- }
-
- if (netdev->macvlan_mode != _NETDEV_MACVLAN_MODE_INVALID) {
- r = sd_rtnl_message_append_u32(req, IFLA_MACVLAN_MODE, netdev->macvlan_mode);
- if (r < 0) {
- log_error_netdev(netdev,
- "Could not append IFLA_MACVLAN_MODE attribute: %s",
- strerror(-r));
- return r;
- }
- }
-
- r = sd_rtnl_message_close_container(req);
- if (r < 0) {
- log_error_netdev(netdev,
- "Could not close IFLA_INFO_DATA container %s",
- strerror(-r));
+ if (netdev->macvlan_mode != _NETDEV_MACVLAN_MODE_INVALID) {
+ r = sd_rtnl_message_append_u32(req, IFLA_MACVLAN_MODE, netdev->macvlan_mode);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_MACVLAN_MODE attribute: %s",
+ strerror(-r));
return r;
}
}
@@ -340,6 +322,14 @@ static int netdev_create(NetDev *netdev, Link *link, sd_rtnl_message_handler_t c
r = sd_rtnl_message_close_container(req);
if (r < 0) {
log_error_netdev(netdev,
+ "Could not close IFLA_INFO_DATA container %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_close_container(req);
+ if (r < 0) {
+ log_error_netdev(netdev,
"Could not close IFLA_LINKINFO container %s",
strerror(-r));
return r;