summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-03-24 00:07:46 +0100
committerTom Gundersen <teg@jklm.no>2014-03-24 16:59:30 +0100
commitd39edfc72f9296078a18014627bf0a2543b60627 (patch)
tree8bc4b060769d43e8e519652dcf2f4ef7cee14733 /src/network
parent3dd215e056ee9ff23175eca66686ff9b7a566dbf (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')
-rw-r--r--src/network/networkd-manager.c2
-rw-r--r--src/network/networkd-netdev.c54
-rw-r--r--src/network/networkd.h2
3 files changed, 41 insertions, 17 deletions
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 46815e0fd0..684b1c7ad3 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -324,7 +324,7 @@ static int manager_rtnl_process_link(sd_rtnl *rtnl, sd_rtnl_message *message, vo
r = netdev_get(m, name, &netdev);
if (r >= 0) {
- r = netdev_set_ifindex(netdev, ifindex);
+ r = netdev_set_ifindex(netdev, message);
if (r < 0)
log_debug("could not set ifindex of netdev '%s' to %d: %s",
name, ifindex, strerror(-r));
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;
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 239ef1cd38..8144031a99 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -264,7 +264,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(NetDev*, netdev_free);
#define _cleanup_netdev_free_ _cleanup_(netdev_freep)
int netdev_get(Manager *manager, const char *name, NetDev **ret);
-int netdev_set_ifindex(NetDev *netdev, int ifindex);
+int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *newlink);
int netdev_enslave(NetDev *netdev, Link *link, sd_rtnl_message_handler_t cb);
const char *netdev_kind_to_string(NetDevKind d) _const_;