summaryrefslogtreecommitdiff
path: root/src/network/networkd-link.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-02-18 21:42:05 +0100
committerTom Gundersen <teg@jklm.no>2014-02-18 22:34:26 +0100
commit11a7f22939d21558df919cab44b8fbe36ab5dae0 (patch)
treeca9d1173cd160446c1b761d807fea4972cc87b87 /src/network/networkd-link.c
parent3302da4667640ac130956d8d90be7c39fb39222f (diff)
networkd: refactor link_add() :(
Don't set set **ret when returning r < 0, as matching on the errno may easily give false positives in the future leading to null pointer dereference. Reported-by: David Herrmann <dh.herrmann@gmail.com>
Diffstat (limited to 'src/network/networkd-link.c')
-rw-r--r--src/network/networkd-link.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index ec283d5b7b..66bcb6bacf 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -85,22 +85,33 @@ void link_free(Link *link) {
free(link);
}
+int link_get(Manager *m, int ifindex, Link **ret) {
+ Link *link;
+ uint64_t ifindex_64;
+
+ assert(m);
+ assert(m->links);
+ assert(ifindex);
+ assert(ret);
+
+ ifindex_64 = ifindex;
+ link = hashmap_get(m->links, &ifindex_64);
+ if (!link)
+ return -ENODEV;
+
+ *ret = link;
+
+ return 0;
+}
+
int link_add(Manager *m, struct udev_device *device, Link **ret) {
Link *link;
Network *network;
int r;
- uint64_t ifindex;
assert(m);
assert(device);
- ifindex = udev_device_get_ifindex(device);
- link = hashmap_get(m->links, &ifindex);
- if (link) {
- *ret = link;
- return -EEXIST;
- }
-
r = link_new(m, device, &link);
if (r < 0)
return r;
@@ -926,7 +937,8 @@ static int link_enter_enslave(Link *link) {
return 0;
}
-static int link_get_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
+static int link_getlink_handler(sd_rtnl *rtnl, sd_rtnl_message *m,
+ void *userdata) {
Link *link = userdata;
int r;
@@ -953,7 +965,7 @@ static int link_get_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
return 1;
}
-static int link_get(Link *link) {
+static int link_getlink(Link *link) {
_cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
int r;
@@ -970,7 +982,8 @@ static int link_get(Link *link) {
return r;
}
- r = sd_rtnl_call_async(link->manager->rtnl, req, link_get_handler, link, 0, NULL);
+ r = sd_rtnl_call_async(link->manager->rtnl, req, link_getlink_handler,
+ link, 0, NULL);
if (r < 0) {
log_error_link(link,
"Could not send rtnetlink message: %s", strerror(-r));
@@ -987,7 +1000,7 @@ int link_configure(Link *link) {
assert(link->network);
assert(link->state == _LINK_STATE_INVALID);
- r = link_get(link);
+ r = link_getlink(link);
if (r < 0) {
link_enter_failed(link);
return r;