[systemd-commits] 2 commits - src/libsystemd src/network TODO
Tom Gundersen
tomegun at kemper.freedesktop.org
Sat Mar 15 12:22:20 PDT 2014
TODO | 1
src/libsystemd/sd-rtnl/rtnl-message.c | 5 --
src/network/networkd-netdev.c | 75 ++++++++++++++++++++++++++++++++++
3 files changed, 78 insertions(+), 3 deletions(-)
New commits:
commit e09826dcf13a17cd63d900502282c511a06ecbe8
Author: Tom Gundersen <teg at jklm.no>
Date: Sat Mar 15 20:03:34 2014 +0100
networkd: netdev - support joining already existing netdevs
diff --git a/TODO b/TODO
index e823f0a..efaded7 100644
--- a/TODO
+++ b/TODO
@@ -667,6 +667,7 @@ Features:
- add support for more attribute types
* networkd:
+ - make sure RTM_NEWLINK messages match both the ifname and kind when setting the ifindex of a netdev
- add more keys to [Route] and [Address] sections
- add support for more DHCPv4 options (and, longer term, other kinds of dynamic config)
- add proper initrd support (in particular generate .network/.link files based on /proc/cmdline)
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index 5796032..298bf27 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -154,6 +154,78 @@ static int netdev_enter_ready(NetDev *netdev) {
return 0;
}
+static int netdev_getlink_handler(sd_rtnl *rtnl, sd_rtnl_message *m,
+ void *userdata) {
+ NetDev *netdev = userdata;
+ int r, ifindex;
+
+ assert(netdev);
+
+ if (netdev->state == NETDEV_STATE_FAILED)
+ return 1;
+
+ r = sd_rtnl_message_get_errno(m);
+ if (r < 0) {
+ log_struct_netdev(LOG_ERR, netdev,
+ "MESSAGE=%s: could not get link: %s",
+ netdev->name, strerror(-r),
+ "ERRNO=%d", -r,
+ NULL);
+ 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);
+
+ return 1;
+}
+
+static int netdev_getlink(NetDev *netdev) {
+ _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
+ int r;
+
+ assert(netdev->manager);
+ assert(netdev->manager->rtnl);
+ assert(netdev->name);
+
+ log_debug_netdev(netdev, "requesting netdev status");
+
+ r = sd_rtnl_message_new_link(netdev->manager->rtnl, &req,
+ RTM_GETLINK, 0);
+ if (r < 0) {
+ log_error_netdev(netdev, "Could not allocate RTM_GETLINK message");
+ return r;
+ }
+
+ r = sd_rtnl_message_append_string(req, IFLA_IFNAME, netdev->name);
+ if (r < 0) {
+ log_error_netdev(netdev, "Colud not append ifname to message: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_call_async(netdev->manager->rtnl, req, netdev_getlink_handler,
+ netdev, 0, NULL);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not send rtnetlink message: %s", strerror(-r));
+ return r;
+ }
+
+ return 0;
+}
+
static int netdev_create_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
NetDev *netdev = userdata;
int r;
@@ -161,6 +233,9 @@ static int netdev_create_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userda
assert(netdev->state != _NETDEV_STATE_INVALID);
r = sd_rtnl_message_get_errno(m);
+ if (r == -EEXIST)
+ r = netdev_getlink(netdev);
+
if (r < 0) {
log_warning_netdev(netdev, "netdev failed: %s", strerror(-r));
netdev_enter_failed(netdev);
commit 6a8402d956a6f89910530e6b364c79be821d2d9d
Author: Tom Gundersen <teg at jklm.no>
Date: Sat Mar 15 20:02:24 2014 +0100
sd-rtnl: make RTM_NEWLINK report EEXIST by default
Use RTM_SETLINK to update an existing link.
diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c
index fca1ff6..7ea68f1 100644
--- a/src/libsystemd/sd-rtnl/rtnl-message.c
+++ b/src/libsystemd/sd-rtnl/rtnl-message.c
@@ -166,8 +166,7 @@ int sd_rtnl_message_new_link(sd_rtnl *rtnl, sd_rtnl_message **ret,
int r;
assert_return(rtnl_message_type_is_link(nlmsg_type), -EINVAL);
- assert_return(nlmsg_type == RTM_NEWLINK ||
- nlmsg_type == RTM_SETLINK || index > 0, -EINVAL);
+ assert_return(nlmsg_type != RTM_DELLINK || index > 0, -EINVAL);
assert_return(ret, -EINVAL);
r = message_new(rtnl, ret, NLMSG_SPACE(sizeof(struct ifinfomsg)));
@@ -177,7 +176,7 @@ int sd_rtnl_message_new_link(sd_rtnl *rtnl, sd_rtnl_message **ret,
(*ret)->hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
(*ret)->hdr->nlmsg_type = nlmsg_type;
if (nlmsg_type == RTM_NEWLINK)
- (*ret)->hdr->nlmsg_flags |= NLM_F_CREATE;
+ (*ret)->hdr->nlmsg_flags |= NLM_F_CREATE | NLM_F_EXCL;
ifi = NLMSG_DATA((*ret)->hdr);
More information about the systemd-commits
mailing list