summaryrefslogtreecommitdiff
path: root/ethtool.c
diff options
context:
space:
mode:
authorBen Hutchings <bhutchings@solarflare.com>2012-06-13 00:57:06 +0100
committerBen Hutchings <bhutchings@solarflare.com>2012-06-13 01:07:38 +0100
commit1eef67710d3f7ddd4fc5ac601c6f2745f5358ba6 (patch)
tree0a8d4f67dde341f1d6ac2865b3864911aa31741a /ethtool.c
parent5c858e25fcc9737d4e866b2da78d4822fb2c2fec (diff)
downloadethtool-1eef67710d3f7ddd4fc5ac601c6f2745f5358ba6.tar.gz
ethtool: Handle more errors when getting feature names
'ethtool -k eth0' generally works for unprivileged users, but in some kernel versions ETHTOOL_GSSET_INFO wrongly returns -EPERM. We need to fall back to the old offload operations in this case. Also, if we get some other error code, report that before exiting. Add regression test cases covering this and some other operations that may fail (which were already handled correctly). Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Diffstat (limited to 'ethtool.c')
-rw-r--r--ethtool.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/ethtool.c b/ethtool.c
index 984273b..3c34273 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -1360,6 +1360,10 @@ static struct feature_defs *get_feature_defs(struct cmd_context *ctx)
} else if (errno == EOPNOTSUPP || errno == EINVAL) {
/* Kernel doesn't support named features; not an error */
n_features = 0;
+ } else if (errno == EPERM) {
+ /* Kernel bug: ETHTOOL_GSSET_INFO was privileged.
+ * Work around it. */
+ n_features = 0;
} else {
return NULL;
}
@@ -1873,8 +1877,10 @@ static int do_gfeatures(struct cmd_context *ctx)
exit_bad_args();
defs = get_feature_defs(ctx);
- if (!defs)
+ if (!defs) {
+ perror("Cannot get device feature names");
return 1;
+ }
fprintf(stdout, "Features for %s:\n", ctx->devname);
@@ -1902,8 +1908,10 @@ static int do_sfeatures(struct cmd_context *ctx)
int i, j;
defs = get_feature_defs(ctx);
- if (!defs)
+ if (!defs) {
+ perror("Cannot get device feature names");
return 1;
+ }
if (defs->n_features) {
efeatures = malloc(sizeof(*efeatures) +
FEATURE_BITS_TO_BLOCKS(defs->n_features) *