X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flibsystemd-rtnl%2Frtnl-util.c;h=dfc0050def3d70b44b552010c1efb97009cf9a22;hp=bf6bf27bb45e036d781b4a385ddef9359f4ad762;hb=eca7a27add5aa3ec85c272fc4cef287fdca034ce;hpb=d8921c6d5c7f1047762c2929908fa6c9b506d59d;ds=sidebyside
diff --git a/src/libsystemd-rtnl/rtnl-util.c b/src/libsystemd-rtnl/rtnl-util.c
index bf6bf27bb..dfc0050de 100644
--- a/src/libsystemd-rtnl/rtnl-util.c
+++ b/src/libsystemd-rtnl/rtnl-util.c
@@ -19,34 +19,63 @@
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, &message);
+ if (r < 0)
+ return r;
+
+ r = sd_rtnl_message_append_string(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, &message);
if (r < 0)
return r;
- if (name) {
- r = sd_rtnl_message_append(message, IFLA_IFNAME, name);
+ if (alias) {
+ r = sd_rtnl_message_append_string(message, IFLA_IFALIAS, alias);
if (r < 0)
return r;
need_update = true;
+
}
if (mac) {
- r = sd_rtnl_message_append(message, IFLA_ADDRESS, mac);
+ r = sd_rtnl_message_append_ether_addr(message, IFLA_ADDRESS, mac);
if (r < 0)
return r;
@@ -54,7 +83,7 @@ int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *name, const
}
if (mtu > 0) {
- r = sd_rtnl_message_append(message, IFLA_MTU, &mtu);
+ r = sd_rtnl_message_append_u32(message, IFLA_MTU, mtu);
if (r < 0)
return r;
@@ -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;
}