[systemd-commits] 2 commits - man/systemd-networkd.service.xml man/udev.xml src/network src/udev TODO
Tom Gundersen
tomegun at kemper.freedesktop.org
Tue Feb 18 22:34:24 CET 2014
TODO | 1
man/systemd-networkd.service.xml | 3 +-
man/udev.xml | 3 +-
src/network/networkd-link.c | 37 +++++++++++++++++++++++------------
src/network/networkd-manager.c | 41 ++++++++++++++++++++-------------------
src/network/networkd-network.c | 2 -
src/network/networkd.h | 1
src/udev/net/link-config.c | 2 -
8 files changed, 54 insertions(+), 36 deletions(-)
New commits:
commit 9b1c2626cef16722603bded9bb52033aba34dd74
Author: Tom Gundersen <teg at jklm.no>
Date: Tue Feb 18 22:06:49 2014 +0100
net-match: fix Driver= match
It should match on the driver of the parent device.
diff --git a/TODO b/TODO
index 925d7a5..57c0572 100644
--- a/TODO
+++ b/TODO
@@ -639,7 +639,6 @@ Features:
- Make sure ID_PATH is always exported and complete for
network devices where possible, so we can safely rely
on Path= matching
- - Check if Driver= is broken, or just my driver (bcma)
* sd-rtnl:
- add support for exiting containers without reading them fully first
diff --git a/man/systemd-networkd.service.xml b/man/systemd-networkd.service.xml
index 9c7ca83..04fedc5 100644
--- a/man/systemd-networkd.service.xml
+++ b/man/systemd-networkd.service.xml
@@ -165,7 +165,8 @@
<term><varname>Driver</varname></term>
<listitem>
<para>The driver currently bound to the device, as
- exposed by the udev property <literal>DRIVER</literal>.
+ exposed by the udev property <literal>DRIVER</literal>
+ of its parent device.
</para>
</listitem>
</varlistentry>
diff --git a/man/udev.xml b/man/udev.xml
index 54a2dd3..eab5d25 100644
--- a/man/udev.xml
+++ b/man/udev.xml
@@ -805,7 +805,8 @@
<varlistentry>
<term><varname>Driver</varname></term>
<listitem>
- <para>The driver currently bound to the device, as exposed by the udev property <literal>DRIVER</literal>.</para>
+ <para>The driver currently bound to the device, as exposed by the
+ udev property <literal>DRIVER</literal> of its parent device.</para>
</listitem>
</varlistentry>
<varlistentry>
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 48131c1..a470c22 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -178,7 +178,7 @@ int network_get(Manager *manager, struct udev_device *device, Network **ret) {
network->match_name,
udev_device_get_sysattr_value(device, "address"),
udev_device_get_property_value(device, "ID_PATH"),
- udev_device_get_driver(device),
+ udev_device_get_driver(udev_device_get_parent(device)),
udev_device_get_devtype(device),
udev_device_get_sysname(device))) {
log_debug("%s: found matching network '%s'",
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index bd97cd8..3afaff1 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -244,7 +244,7 @@ int link_config_get(link_config_ctx *ctx, struct udev_device *device, link_confi
link->match_driver, link->match_type, NULL,
udev_device_get_sysattr_value(device, "address"),
udev_device_get_property_value(device, "ID_PATH"),
- udev_device_get_driver(device),
+ udev_device_get_driver(udev_device_get_parent(device)),
udev_device_get_devtype(device),
NULL)) {
log_debug("Config file %s applies to device %s",
commit 11a7f22939d21558df919cab44b8fbe36ab5dae0
Author: Tom Gundersen <teg at jklm.no>
Date: Tue Feb 18 21:42:05 2014 +0100
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 at gmail.com>
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index ec283d5..66bcb6b 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;
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index c1ad69b..f817d69 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -145,30 +145,31 @@ bool manager_should_reload(Manager *m) {
}
static int manager_process_link(Manager *m, struct udev_device *device) {
- Link *link;
+ Link *link = NULL;
int r;
- if (streq_ptr(udev_device_get_action(device), "remove")) {
- uint64_t ifindex;
+ assert(m);
+ assert(device);
+ link_get(m, udev_device_get_ifindex(device), &link);
+
+ if (streq_ptr(udev_device_get_action(device), "remove")) {
log_debug("%s: link removed", udev_device_get_sysname(device));
- ifindex = udev_device_get_ifindex(device);
- link = hashmap_get(m->links, &ifindex);
- if (!link)
+ if (link)
+ link_free(link);
+ } else {
+ if (link) {
+ log_debug("%s: link already exists, ignoring",
+ link->ifname);
return 0;
+ }
- link_free(link);
- } else {
r = link_add(m, device, &link);
if (r < 0) {
- if (r == -EEXIST)
- log_debug("%s: link already exists, ignoring",
- link->ifname);
- else
- log_error("%s: could not handle link: %s",
- udev_device_get_sysname(device),
- strerror(-r));
+ log_error("%s: could not handle link: %s",
+ udev_device_get_sysname(device),
+ strerror(-r));
} else
log_debug("%s: link (with ifindex %" PRIu64") added",
link->ifname, link->ifindex);
@@ -264,9 +265,12 @@ static int manager_rtnl_process_link(sd_rtnl *rtnl, sd_rtnl_message *message, vo
Manager *m = userdata;
Link *link;
const char *name;
- uint64_t ifindex_64;
int r, ifindex;
+ assert(rtnl);
+ assert(message);
+ assert(m);
+
r = sd_rtnl_message_link_get_ifindex(message, &ifindex);
if (r < 0 || ifindex <= 0) {
log_debug("received RTM_NEWLINK message without valid ifindex");
@@ -288,9 +292,8 @@ static int manager_rtnl_process_link(sd_rtnl *rtnl, sd_rtnl_message *message, vo
}
}
- ifindex_64 = ifindex;
- link = hashmap_get(m->links, &ifindex_64);
- if (!link) {
+ r = link_get(m, ifindex, &link);
+ if (r < 0) {
log_debug("received RTM_NEWLINK message for untracked ifindex %d", ifindex);
return 0;
}
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 51d7757..5a1bf1a 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -313,6 +313,7 @@ int config_parse_label(const char *unit, const char *filename, unsigned line,
int link_new(Manager *manager, struct udev_device *device, Link **ret);
void link_free(Link *link);
+int link_get(Manager *m, int ifindex, Link **ret);
int link_add(Manager *manager, struct udev_device *device, Link **ret);
int link_configure(Link *link);
More information about the systemd-commits
mailing list