chiark / gitweb /
bus: fix typo in systemd-bus-proxyd
[elogind.git] / src / libsystemd-rtnl / rtnl-util.c
index 9707aa04a661496bf5386f0d378439e1392661f3..dfc0050def3d70b44b552010c1efb97009cf9a22 100644 (file)
@@ -34,22 +34,23 @@ int rtnl_set_link_name(sd_rtnl *rtnl, int ifindex, const char *name) {
         assert(ifindex > 0);
         assert(name);
 
-        r = sd_rtnl_message_link_new(RTM_NEWLINK, ifindex, 0, 0, &message);
+        r = sd_rtnl_message_link_new(RTM_SETLINK, ifindex, &message);
         if (r < 0)
                 return r;
 
-        r = sd_rtnl_message_append(message, IFLA_IFNAME, name);
+        r = sd_rtnl_message_append_string(message, IFLA_IFNAME, name);
         if (r < 0)
                 return r;
 
-        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;
 
         return 0;
 }
 
-int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const struct ether_addr *mac, unsigned mtu) {
+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;
@@ -57,15 +58,24 @@ int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const struct ether_addr
         assert(rtnl);
         assert(ifindex > 0);
 
-        if (!mac && mtu == 0)
+        if (!alias && !mac && mtu == 0)
                 return 0;
 
-        r = sd_rtnl_message_link_new(RTM_NEWLINK, ifindex, 0, 0, &message);
+        r = sd_rtnl_message_link_new(RTM_SETLINK, ifindex, &message);
         if (r < 0)
                 return r;
 
+        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;
 
@@ -73,7 +83,7 @@ int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const struct ether_addr
         }
 
         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;
 
@@ -81,7 +91,7 @@ int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const struct ether_addr
         }
 
         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;
         }