From d8e538ecd9e62f841242f07e3df5c835c1ba6313 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Wed, 26 Mar 2014 19:25:01 +0100 Subject: 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. --- src/network/networkd-netdev.c | 52 +++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) (limited to 'src/network') 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,52 +291,42 @@ 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; } } + 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, -- cgit v1.2.3-54-g00ecf