From c3ebdce39a748f738f3731730cd085ff3551b379 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Mon, 24 Mar 2014 21:50:16 +0100 Subject: networkd: netdev - fix error handling in set_ifindex() Firstly, remove stray assert(). Also be a bit stricter when verifying the received info. If we get an applicable newlink message that we can't make sense of, we will now enter NETDEV_FAILED, as we cannot reasonably continue without knowing the ifindex of our device. --- src/network/networkd-netdev.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c index 356341a873..cdf07ad704 100644 --- a/src/network/networkd-netdev.c +++ b/src/network/networkd-netdev.c @@ -381,16 +381,20 @@ int netdev_enslave(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callbac } int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *message) { + uint16_t type; const char *kind; char *received_kind; int r, ifindex; assert(netdev); - assert(ifindex > 0); + assert(message); - kind = netdev_kind_to_string(netdev->kind); - if (!kind) - log_error_netdev(netdev, "Could not get kind"); + r = sd_rtnl_message_get_type(message, &type); + if (r < 0) + return r; + + if (type != RTM_NEWLINK) + return -EINVAL; r = sd_rtnl_message_enter_container(message, IFLA_LINKINFO); if (r < 0) { @@ -404,6 +408,13 @@ int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *message) { return r; } + kind = netdev_kind_to_string(netdev->kind); + if (!kind) { + log_error_netdev(netdev, "Could not get kind"); + netdev_enter_failed(netdev); + return -EINVAL; + } + if (!streq(kind, received_kind)) { log_error_netdev(netdev, "Received newlink with wrong KIND"); netdev_enter_failed(netdev); @@ -412,11 +423,12 @@ int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *message) { r = sd_rtnl_message_link_get_ifindex(message, &ifindex); if (r < 0) { - log_struct_netdev(LOG_ERR, netdev, - "MESSAGE=%s: could not get ifindex: %s", - netdev->name, strerror(-r), - "ERRNO=%d", -r, - NULL); + log_error_netdev(netdev, "Could not get ifindex: %s", strerror(-r)); + netdev_enter_failed(netdev); + return r; + } else if (ifindex <= 0) { + log_error_netdev(netdev, "Got invalid ifindex: %d", ifindex); + netdev_enter_failed(netdev); return r; } -- cgit v1.2.3-54-g00ecf