]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
lib: Dump ext-ack string by default
authorDavid Ahern <dsahern@gmail.com>
Wed, 9 Aug 2017 15:43:27 +0000 (08:43 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 9 Aug 2017 16:14:01 +0000 (09:14 -0700)
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.

Signed-off-by: David Ahern <dsahern@gmail.com>
lib/libnetlink.c

index 145de2cb0ccfe3dc7d93ba4ff4e9a9d40e77c5e7..81a344abff27a6f65d59a6c229741cf1b8344171 100644 (file)
@@ -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,19 @@ 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 && *errmsg != '\0') {
+               fprintf(stderr, "Error: %s", errmsg);
+               if (errmsg[strlen(errmsg) - 1] != '.')
+                       fprintf(stderr, ".");
+               fprintf(stderr, "\n");
+
+               return 1;
+       }
+
+       return 0;
 }
 #else
 #warning "libmnl required for error support"