summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-03-24 21:50:16 +0100
committerTom Gundersen <teg@jklm.no>2014-03-24 22:09:06 +0100
commitc3ebdce39a748f738f3731730cd085ff3551b379 (patch)
tree30cb6110109acb6a765c88c406535c053e5e80ae /src/network
parentc4bfd1691f4d3e26d6d7f34dbca941e119956e8a (diff)
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.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkd-netdev.c30
1 files changed, 21 insertions, 9 deletions
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;
}