From patchwork Wed Dec 17 07:28:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Duan Jiong X-Patchwork-Id: 422185 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 09C0B1400DD for ; Wed, 17 Dec 2014 18:29:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751274AbaLQH2u (ORCPT ); Wed, 17 Dec 2014 02:28:50 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:29288 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751137AbaLQH2s (ORCPT ); Wed, 17 Dec 2014 02:28:48 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="45318807" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 17 Dec 2014 15:25:27 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id sBH7SLvN022244; Wed, 17 Dec 2014 15:28:21 +0800 Received: from [10.167.225.86] (10.167.225.86) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.181.6; Wed, 17 Dec 2014 15:28:56 +0800 Message-ID: <549130AD.6090407@cn.fujitsu.com> Date: Wed, 17 Dec 2014 15:28:45 +0800 From: Duan Jiong User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0 MIME-Version: 1.0 To: stephen hemminger CC: netdev Subject: [PATCH iproute2] ip link: use addattr_nest()/addattr_nest_end() X-Originating-IP: [10.167.225.86] Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use addattr_nest() and addattr_nest_end() to simplify the code. Signed-off-by: Duan Jiong --- ip/iplink.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ip/iplink.c b/ip/iplink.c index ce6eb3e..3ce5e39 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -706,11 +706,11 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) } if (type) { - struct rtattr *linkinfo = NLMSG_TAIL(&req.n); + struct rtattr *linkinfo; char slavebuf[128], *ulinep = strchr(type, '_'); int iflatype; - addattr_l(&req.n, sizeof(req), IFLA_LINKINFO, NULL, 0); + linkinfo = addattr_nest(&req.n, sizeof(req), IFLA_LINKINFO); addattr_l(&req.n, sizeof(req), IFLA_INFO_KIND, type, strlen(type)); @@ -728,14 +728,13 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) iflatype = IFLA_INFO_DATA; } if (lu && argc) { - struct rtattr * data = NLMSG_TAIL(&req.n); - addattr_l(&req.n, sizeof(req), iflatype, NULL, 0); + struct rtattr *data = addattr_nest(&req.n, sizeof(req), iflatype); if (lu->parse_opt && lu->parse_opt(lu, argc, argv, &req.n)) return -1; - data->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)data; + addattr_nest_end(&req.n, data); } else if (argc) { if (matches(*argv, "help") == 0) usage(); @@ -743,7 +742,7 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) "Try \"ip link help\".\n", *argv); return -1; } - linkinfo->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)linkinfo; + addattr_nest_end(&req.n, linkinfo); } else if (flags & NLM_F_CREATE) { fprintf(stderr, "Not enough information: \"type\" argument " "is required\n");