Skip to contentSkip to conversation

lib: Dump ext-ack string by default

PATCH Superseded David Ahern 2 participants 3 messages Aug 8, 2017 – Aug 9, 2017

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 lib: Dump ext-ack string by default

In time, errfn can be implemented for link, route, etc commands to give a much more detailed response (e.g., point to the attribute that failed). Doing so is much more complicated to process the message and convert attribute ids to names.

In any case the error string returned by the kernel should be dumped to the user, so make that happen now.

---
v2
- check that errmsg is non-null

 lib/libnetlink.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
lib/libnetlink.c +10 -5
index 145de2cb0ccf..063f5cd6c7b1 100644
@@ -61,7 +61,6 @@ static int err_attr_cb(const struct nlattr *attr, void *data)
 	return MNL_CB_OK;
 }
 
-
 /* dump netlink extended ack error message */
 static int nl_dump_ext_err(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
 {
@@ -72,9 +71,6 @@ static int nl_dump_ext_err(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
 	const char *errmsg = NULL;
 	uint32_t off = 0;
 
-	if (!errfn)
-		return 0;
-
 	/* no TLVs, nothing to do here */
 	if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS))
 		return 0;
@@ -99,7 +95,16 @@ static int nl_dump_ext_err(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
 			err_nlh = &err->msg;
 	}
 
-	return errfn(errmsg, off, err_nlh);
+	if (errfn)
+		return errfn(errmsg, off, err_nlh);
+
+	if (errmsg) {
+		fprintf(stderr, "Error: %s\n", errmsg);
+
+		return 1;
+	}
+
+	return 0;
 }
 #else
 #warning "libmnl required for error support"
Signature · 1 line
2.1.4
#1 lore raw
Quoted 39 lines · David Ahern

In time, errfn can be implemented for link, route, etc commands to give a much more detailed response (e.g., point to the attribute that failed). Doing so is much more complicated to process the message and convert attribute ids to names.

In any case the error string returned by the kernel should be dumped to the user, so make that happen now.

---
v2
- check that errmsg is non-null

  lib/libnetlink.c | 15 ++++++++++-----
  1 file changed, 10 insertions(+), 5 deletions(-)
lib/libnetlink.c +0 -4
index 145de2cb0ccf..063f5cd6c7b1 100644
@@ -61,7 +61,6 @@ static int err_attr_cb(const struct nlattr *attr, void *data)
  	return MNL_CB_OK;
  }
 
-
  /* dump netlink extended ack error message */
  static int nl_dump_ext_err(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
  {
@@ -72,9 +71,6 @@ static int nl_dump_ext_err(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
  	const char *errmsg = NULL;
  	uint32_t off = 0;
 
-	if (!errfn)
-		return 0;
-
  	/* no TLVs, nothing to do here */
  	if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS))
  		return 0;

lib/libnetlink.c static int nl_dump_ext_err(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn) · line 102

Quoted 9 lines
lib/libnetlink.c +5 -1
@@ -99,7 +95,16 @@ static int nl_dump_ext_err(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
  			err_nlh = &err->msg;
  	}
 
-	return errfn(errmsg, off, err_nlh);
+	if (errfn)
+		return errfn(errmsg, off, err_nlh);
+
+	if (errmsg) {
+		fprintf(stderr, "Error: %s\n", errmsg);

Should the above output end with a period '.'? All the error messages in the Kernel are statements without a terminating period, so the output will look something like this..

Error: Minimally Geneve ID and Remote IP address are required
Error: Provided Ethernet address is not unicast
Error: Provided link layer address is not Ethernet

Thanks,
~Girish

Quoted 9 lines
lib/libnetlink.c +5 -0
+
+		return 1;
+	}
+
+	return 0;
  }
  #else
  #warning "libmnl required for error support"
#2 lore raw
Quoted 5 lines · Girish Moodalbail
Quoted 5 lines
lib/libnetlink.c +0 -0
@@ -99,7 +95,16 @@ static int nl_dump_ext_err(const struct nlmsghdr
 *nlh, nl_ext_ack_fn_t errfn)
              err_nlh = &err->msg;
      }
  -    return errfn(errmsg, off, err_nlh);
Quoted 8 lines

lib/libnetlink.c static int nl_dump_ext_err(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn) · line 102

Quoted 5 lines
lib/libnetlink.c +5 -0
+    if (errfn)
+        return errfn(errmsg, off, err_nlh);
+
+    if (errmsg) {
+        fprintf(stderr, "Error: %s\n", errmsg);

Should the above output end with a period '.'? All the error messages in the Kernel are statements without a terminating period, so the output

no guarantee of that, but iproute2 could check for it and add it.