summaryrefslogtreecommitdiff
path: root/src/udev/net/link-config.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2013-10-26 18:54:16 +0200
committerTom Gundersen <teg@jklm.no>2013-10-26 22:09:20 +0200
commita501033335ed402c8f7e86fe41a15531ba69abd7 (patch)
treeb5e8a1a12adaaa3168a4c0cedc40c0f584190d69 /src/udev/net/link-config.c
parentaf6f0d422c521374ee6a2dd92df5935a5a476ae5 (diff)
udev: link-config: add ethtool support
This adds support for setting the link speed, duplex and WakeOnLan settings. Example: [Link] SpeedMBytes=100 Duplex=half WakeOnLan=magic
Diffstat (limited to 'src/udev/net/link-config.c')
-rw-r--r--src/udev/net/link-config.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index 7686d87f80..3beb28acba 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -21,6 +21,8 @@
#include "link-config.h"
+#include "ethtool-util.h"
+
#include "util.h"
#include "log.h"
#include "strv.h"
@@ -31,12 +33,15 @@
struct link_config_ctx {
LIST_HEAD(link_config, links);
+ int ethtool_fd;
+
char **link_dirs;
usec_t *link_dirs_ts_usec;
};
int link_config_ctx_new(link_config_ctx **ret) {
link_config_ctx *ctx;
+ int r;
if (!ret)
return -EINVAL;
@@ -45,6 +50,12 @@ int link_config_ctx_new(link_config_ctx **ret) {
if (!ctx)
return -ENOMEM;
+ r = ethtool_connect(&ctx->ethtool_fd);
+ if (r < 0) {
+ link_config_ctx_free(ctx);
+ return r;
+ }
+
LIST_HEAD_INIT(ctx->links);
ctx->link_dirs = strv_new("/etc/net/links",
@@ -93,6 +104,7 @@ void link_config_ctx_free(link_config_ctx *ctx) {
if (!ctx)
return;
+ close_nointr_nofail(ctx->ethtool_fd);
strv_free(ctx->link_dirs);
free(ctx->link_dirs_ts_usec);
link_configs_free(ctx);
@@ -233,11 +245,34 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_dev
log_info("Configuring %s", name);
if (config->description) {
- r = udev_device_set_sysattr_value(device, "ifalias", config->description);
+ r = udev_device_set_sysattr_value(device, "ifalias",
+ config->description);
+ if (r < 0)
+ log_warning("Could not set description of %s to '%s': %s",
+ name, config->description, strerror(-r));
+ else
+ log_info("Set link description of %s to '%s'", name,
+ config->description);
+ }
+
+ if (config->speed || config->duplex) {
+ r = ethtool_set_speed(ctx->ethtool_fd, name,
+ config->speed, config->duplex);
+ if (r < 0)
+ log_warning("Could not set speed or duplex of %s to %u Mbytes (%s): %s",
+ name, config->speed, config->duplex, strerror(-r));
+ else
+ log_info("Set speed or duplex of %s to %u Mbytes (%s)", name,
+ config->speed, config->duplex);
+ }
+
+ if (config->wol) {
+ r = ethtool_set_wol(ctx->ethtool_fd, name, config->wol);
if (r < 0)
- log_warning("Could not set description of %s to '%s': %s", name, config->description, strerror(-r));
+ log_warning("Could not set WakeOnLan of %s to %s: %s",
+ name, config->wol, strerror(-r));
else
- log_info("Set link description of %s to '%s'", name, config->description);
+ log_info("Set WakeOnLan of %s to %s", name, config->wol);
}
return 0;