X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd-rtnl%2Frtnl-util.c;h=4e7661bb7775a1185d8c7eb31e108f4793bc83d4;hb=815ebc540daf5cede58570bbeb0a4106e201c52e;hp=bf6bf27bb45e036d781b4a385ddef9359f4ad762;hpb=d8921c6d5c7f1047762c2929908fa6c9b506d59d;p=elogind.git
diff --git a/src/libsystemd-rtnl/rtnl-util.c b/src/libsystemd-rtnl/rtnl-util.c
index bf6bf27bb..4e7661bb7 100644
--- a/src/libsystemd-rtnl/rtnl-util.c
+++ b/src/libsystemd-rtnl/rtnl-util.c
@@ -19,30 +19,59 @@
along with systemd; If not, see .
***/
+#include
#include
#include "sd-rtnl.h"
#include "rtnl-util.h"
-int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *name, const struct ether_addr *mac, unsigned mtu) {
- _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *message;
+int rtnl_set_link_name(sd_rtnl *rtnl, int ifindex, const char *name) {
+ _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *message = NULL;
+ int r;
+
+ assert(rtnl);
+ assert(ifindex > 0);
+ assert(name);
+
+ r = sd_rtnl_message_link_new(RTM_SETLINK, ifindex, 0, 0, &message);
+ if (r < 0)
+ return r;
+
+ r = sd_rtnl_message_append(message, IFLA_IFNAME, name);
+ if (r < 0)
+ return r;
+
+ r = sd_rtnl_call(rtnl, message, 0, NULL);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
+int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *alias,
+ const struct ether_addr *mac, unsigned mtu) {
+ _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *message = NULL;
bool need_update = false;
int r;
assert(rtnl);
assert(ifindex > 0);
- r = sd_rtnl_message_link_new(RTM_NEWLINK, ifindex, 0, 0, &message);
+ if (!alias && !mac && mtu == 0)
+ return 0;
+
+ r = sd_rtnl_message_link_new(RTM_SETLINK, ifindex, 0, 0, &message);
if (r < 0)
return r;
- if (name) {
- r = sd_rtnl_message_append(message, IFLA_IFNAME, name);
+ if (alias) {
+ r = sd_rtnl_message_append(message, IFLA_IFALIAS, alias);
if (r < 0)
return r;
need_update = true;
+
}
if (mac) {
@@ -62,7 +91,7 @@ int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *name, const
}
if (need_update) {
- r = sd_rtnl_send_with_reply_and_block(rtnl, message, 0, NULL);
+ r = sd_rtnl_call(rtnl, message, 0, NULL);
if (r < 0)
return r;
}