From patchwork Tue May 2 03:18:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 757370 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3wH62628VBz9sNH for ; Tue, 2 May 2017 13:18:38 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=cumulusnetworks.com header.i=@cumulusnetworks.com header.b="YR4YY0RU"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751244AbdEBDSg (ORCPT ); Mon, 1 May 2017 23:18:36 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:36423 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751194AbdEBDSc (ORCPT ); Mon, 1 May 2017 23:18:32 -0400 Received: by mail-pg0-f41.google.com with SMTP id t7so53616361pgt.3 for ; Mon, 01 May 2017 20:18:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cumulusnetworks.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0701osxXpcTC4j3UFXTm3VBuexjGZJ7f8kTItkz6Bvo=; b=YR4YY0RUKUa6YZr85Zl3ueqUoG5CZmfr+8w96cBUOCCZm6WVD77tloOGoTqaPAIuXv fxANhwYzBL1QL+gmJ0wUbSIaxni528DCKr5rOEAuWsVq/OGhWdZXIbk1wkwwMtICukAe b2a315qN9ijc/rOy3LH055o+S3h0vPTZ9GVos= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0701osxXpcTC4j3UFXTm3VBuexjGZJ7f8kTItkz6Bvo=; b=RrI3HvV+2wLAlIJnQ/Js1xn/emcmZ0bYpXx501zM+Lev1W3guLcO7qWyukmJmhkIrF Sa1udYw2T1PKVsdhlEZJzZniQIEMOz667ERNY8mz7seoNx3P5dPYalzIvTf1+uLROeZc ceyF0lfWCC7Sao/VibBLbUFfYFHCdS3fp4kTJ1wJjZpF/f+WzvXFwxziO9PFpFagNv7/ dlwL9lB7KA0EmehSFf1hlXG7OjybZCiwV/Gx7gB7LLs3/dmn0gg7sEo5VyjAc+V1AxgC Xv4rkju1hHcRTBE5v5U/Jx5C8aWniYIN0Lx3L4KywNgV1rKIglDewHDw4B/nxsUv/eP2 nP2Q== X-Gm-Message-State: AN3rC/5oXWMUDVSLykEzLbuL1s+IV7ZMensSvEM9BRaDPY/baAaiLfEh bt4XuqKzrhpmlxHo X-Received: by 10.99.97.68 with SMTP id v65mr20348242pgb.76.1493695111756; Mon, 01 May 2017 20:18:31 -0700 (PDT) Received: from kenny.it.cumulusnetworks.com. ([216.129.126.126]) by smtp.googlemail.com with ESMTPSA id n126sm25204444pgn.32.2017.05.01.20.18.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 May 2017 20:18:31 -0700 (PDT) From: David Ahern To: netdev@vger.kernel.org, stephen@networkplumber.org Cc: jakub.kicinski@netronome.com, David Ahern Subject: [PATCH net-next iproute2 3/3] ip link: Add extack handling for setlink Date: Mon, 1 May 2017 20:18:25 -0700 Message-Id: <1493695105-9418-4-git-send-email-dsa@cumulusnetworks.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1493695105-9418-1-git-send-email-dsa@cumulusnetworks.com> References: <1493695105-9418-1-git-send-email-dsa@cumulusnetworks.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Flip iplink_modify to rtnl_talk_extack. For this first patch only error messages returned from the kernel are displayed to the user. Follow on patches can add parsing of the returned message and the error offset to show which attribute caused an error. Signed-off-by: David Ahern --- ip/iplink.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ip/iplink.c b/ip/iplink.c index ae1c70ebcc81..aad0220a63a7 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -861,6 +861,19 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, return ret - argc; } +static int iplink_extack(const char *errmsg, __u32 off, + struct nlmsghdr *err_nlh) +{ + int rc = 0; + + if (errmsg) { + rc++; + fprintf(stderr, "Error: %s\n", errmsg); + } + + return rc; +} + static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) { int len; @@ -906,7 +919,8 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) req.i.ifi_index = 0; addattr32(&req.n, sizeof(req), IFLA_GROUP, group); - if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) + if (rtnl_talk_extack(&rth, &req.n, NULL, 0, + iplink_extack) < 0) return -2; return 0; } @@ -1001,7 +1015,7 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) return -1; } - if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) + if (rtnl_talk_extack(&rth, &req.n, NULL, 0, iplink_extack) < 0) return -2; return 0;