From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Ahern Subject: [PATCH iproute2] lib: Dump ext-ack string by default Date: Mon, 7 Aug 2017 12:28:02 -0700 Message-ID: <1502134082-4602-1-git-send-email-dsahern@gmail.com> Cc: David Ahern To: netdev@vger.kernel.org, stephen@networkplumber.org Return-path: Received: from mail-pf0-f194.google.com ([209.85.192.194]:36265 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751699AbdHGT2I (ORCPT ); Mon, 7 Aug 2017 15:28:08 -0400 Received: by mail-pf0-f194.google.com with SMTP id t83so1229874pfj.3 for ; Mon, 07 Aug 2017 12:28:08 -0700 (PDT) Sender: netdev-owner@vger.kernel.org List-ID: 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 --- lib/libnetlink.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 145de2cb0ccf..ee78f768a8bd 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -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,12 @@ 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); + + fprintf(stderr, "Error: %s\n", errmsg); + + return 1; } #else #warning "libmnl required for error support" -- 2.1.4