1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-06 16:59:03 +03:00

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.
This commit is contained in:
Tom Gundersen 2014-03-24 21:50:16 +01:00
parent c4bfd1691f
commit c3ebdce39a

View File

@ -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;
}