diff options
author | Tom Gundersen <teg@jklm.no> | 2014-03-24 00:07:46 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-03-24 16:59:30 +0100 |
commit | d39edfc72f9296078a18014627bf0a2543b60627 (patch) | |
tree | 8bc4b060769d43e8e519652dcf2f4ef7cee14733 /src/network/networkd-netdev.c | |
parent | 3dd215e056ee9ff23175eca66686ff9b7a566dbf (diff) |
networkd: netdev - verify that newlink messages has the expected kind
We match 'newlink' messages with expected netdev's based on their names. Now also
make sure that the receieved link has the expected kind.
Diffstat (limited to 'src/network/networkd-netdev.c')
-rw-r--r-- | src/network/networkd-netdev.c | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c index 3a670b3f0e..356341a873 100644 --- a/src/network/networkd-netdev.c +++ b/src/network/networkd-netdev.c @@ -157,7 +157,7 @@ static int netdev_enter_ready(NetDev *netdev) { static int netdev_getlink_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) { NetDev *netdev = userdata; - int r, ifindex; + int r; assert(netdev); @@ -174,19 +174,7 @@ static int netdev_getlink_handler(sd_rtnl *rtnl, sd_rtnl_message *m, return 1; } - r = sd_rtnl_message_link_get_ifindex(m, &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); - return 1; - } - - r = netdev_set_ifindex(netdev, ifindex); - if (r < 0) - log_warning_netdev(netdev, "could not set ifindex to %d", ifindex); + netdev_set_ifindex(netdev, m); return 1; } @@ -392,10 +380,46 @@ int netdev_enslave(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callbac return 0; } -int netdev_set_ifindex(NetDev *netdev, int ifindex) { +int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *message) { + const char *kind; + char *received_kind; + int r, ifindex; + assert(netdev); assert(ifindex > 0); + kind = netdev_kind_to_string(netdev->kind); + if (!kind) + log_error_netdev(netdev, "Could not get kind"); + + r = sd_rtnl_message_enter_container(message, IFLA_LINKINFO); + if (r < 0) { + log_error_netdev(netdev, "Could not get LINKINFO"); + return r; + } + + r = sd_rtnl_message_read_string(message, IFLA_INFO_KIND, &received_kind); + if (r < 0) { + log_error_netdev(netdev, "Could not get KIND"); + return r; + } + + if (!streq(kind, received_kind)) { + log_error_netdev(netdev, "Received newlink with wrong KIND"); + netdev_enter_failed(netdev); + return r; + } + + 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); + return r; + } + if (netdev->ifindex > 0) { if (netdev->ifindex == ifindex) return 0; |