summaryrefslogtreecommitdiff
path: root/dcb
diff options
context:
space:
mode:
authorPetr Machata <petrm@nvidia.com>2022-02-09 15:41:40 +0100
committerStephen Hemminger <stephen@networkplumber.org>2022-02-16 12:12:19 -0800
commit1b5c7414a42a29d559af85022afebc307a2b9d12 (patch)
tree922c73540cd5d7a759fa0cd860135440b965caa8 /dcb
parenta38d305d15c6a27084d5ebc1c79a831d3ac45b22 (diff)
downloadiproute2-1b5c7414a42a29d559af85022afebc307a2b9d12.tar.gz
dcb: Fix error reporting when accessing "dcb app"
Currently dcb decodes the response from "dcb app add" and "del" by interpreting the returned attribute as u8. But the value stored there is actually a negative errno value. Additionally, "dcb app" currently shows two sets of messages, one in dcb_set_attribute_attr_cb() where the issue is detected, and another as a result of error return from that function. The current state is as follows: # dcb app add dev swp36 dscp-prio 20:2 Error when attempting to set attribute: Unknown error 239 Attribute write: No such file or directory Fix the "unknown error" issue by correctly decoding the attribute as i8 and negating it. Furthermore, set errno to that value, and let the top-level "attribute write" error message show the correct message. Initialize errno to 0 before the dcb_talk() dispatch, and make the error print conditional on errno != 0. This way the few error messages that are worth describing in the place where they are detected will not cause the second error message to be printed. The fixed reporting looks like this: # dcb app add dev swp36 dscp-prio 20:2 Attribute write: File exists Reported-by: Maksym Yaremchuk <maksymy@nvidia.com> Signed-off-by: Petr Machata <petrm@nvidia.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Diffstat (limited to 'dcb')
-rw-r--r--dcb/dcb.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/dcb/dcb.c b/dcb/dcb.c
index b7c2df54..8d75ab0a 100644
--- a/dcb/dcb.c
+++ b/dcb/dcb.c
@@ -106,7 +106,7 @@ static int dcb_set_attribute_attr_cb(const struct nlattr *attr, void *data)
{
struct dcb_set_attribute_response *resp = data;
uint16_t len;
- uint8_t err;
+ int8_t err;
if (mnl_attr_get_type(attr) != resp->response_attr)
return MNL_CB_OK;
@@ -117,10 +117,12 @@ static int dcb_set_attribute_attr_cb(const struct nlattr *attr, void *data)
return MNL_CB_ERROR;
}
+ /* The attribute is formally u8, but actually an i8 containing a
+ * negative errno value.
+ */
err = mnl_attr_get_u8(attr);
if (err) {
- fprintf(stderr, "Error when attempting to set attribute: %s\n",
- strerror(err));
+ errno = -err;
return MNL_CB_ERROR;
}
@@ -242,9 +244,11 @@ static int __dcb_set_attribute(struct dcb *dcb, int command, const char *dev,
if (ret)
return ret;
+ errno = 0;
ret = dcb_talk(dcb, nlh, dcb_set_attribute_cb, &resp);
if (ret) {
- perror("Attribute write");
+ if (errno)
+ perror("Attribute write");
return ret;
}
return 0;