summaryrefslogtreecommitdiff
path: root/src/libsystemd
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-09-09 15:36:56 +0200
committerTom Gundersen <teg@jklm.no>2014-09-09 15:36:56 +0200
commitaedca89268ed4fd6be41e55a605f011033ad1fb5 (patch)
treebf53358d9133f54f5687e3eab93477c1584c9e76 /src/libsystemd
parent4c83d994566718043e61e568cc214bdc4587f869 (diff)
udev: net_setup_link - open ethtool and rtnl connections lazily
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/sd-rtnl/rtnl-util.c26
-rw-r--r--src/libsystemd/sd-rtnl/rtnl-util.h2
2 files changed, 12 insertions, 16 deletions
diff --git a/src/libsystemd/sd-rtnl/rtnl-util.c b/src/libsystemd/sd-rtnl/rtnl-util.c
index fe0f34e125..1ec1fa8d27 100644
--- a/src/libsystemd/sd-rtnl/rtnl-util.c
+++ b/src/libsystemd/sd-rtnl/rtnl-util.c
@@ -55,10 +55,9 @@ int rtnl_set_link_name(sd_rtnl **rtnl, int ifindex, const char *name) {
return 0;
}
-int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *alias,
+int rtnl_set_link_properties(sd_rtnl **rtnl, int ifindex, const char *alias,
const struct ether_addr *mac, unsigned mtu) {
_cleanup_rtnl_message_unref_ sd_rtnl_message *message = NULL;
- bool need_update = false;
int r;
assert(rtnl);
@@ -67,7 +66,13 @@ int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *alias,
if (!alias && !mac && mtu == 0)
return 0;
- r = sd_rtnl_message_new_link(rtnl, &message, RTM_SETLINK, ifindex);
+ if (!*rtnl) {
+ r = sd_rtnl_open(rtnl, 0);
+ if (r < 0)
+ return r;
+ }
+
+ r = sd_rtnl_message_new_link(*rtnl, &message, RTM_SETLINK, ifindex);
if (r < 0)
return r;
@@ -75,32 +80,23 @@ int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *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_ether_addr(message, IFLA_ADDRESS, mac);
if (r < 0)
return r;
-
- need_update = true;
}
if (mtu > 0) {
r = sd_rtnl_message_append_u32(message, IFLA_MTU, mtu);
if (r < 0)
return r;
-
- need_update = true;
}
- if (need_update) {
- r = sd_rtnl_call(rtnl, message, 0, NULL);
- if (r < 0)
- return r;
- }
+ r = sd_rtnl_call(*rtnl, message, 0, NULL);
+ if (r < 0)
+ return r;
return 0;
}
diff --git a/src/libsystemd/sd-rtnl/rtnl-util.h b/src/libsystemd/sd-rtnl/rtnl-util.h
index 94af3b1720..fa3592df9d 100644
--- a/src/libsystemd/sd-rtnl/rtnl-util.h
+++ b/src/libsystemd/sd-rtnl/rtnl-util.h
@@ -35,7 +35,7 @@ bool rtnl_message_type_is_addr(uint16_t type);
bool rtnl_message_type_is_route(uint16_t type);
int rtnl_set_link_name(sd_rtnl **rtnl, int ifindex, const char *name);
-int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *alias, 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);
int rtnl_log_parse_error(int r);
int rtnl_log_create_error(int r);