From: Duan Jiong <duanj.fnst@cn.fujitsu.com>
To: stephen hemminger <stephen@networkplumber.org>
Cc: netdev <netdev@vger.kernel.org>
Subject: [PATCH iproute2] ip link: use addattr_nest()/addattr_nest_end()
Date: Wed, 17 Dec 2014 15:28:45 +0800 [thread overview]
Message-ID: <549130AD.6090407@cn.fujitsu.com> (raw)
Use addattr_nest() and addattr_nest_end() to simplify the code.
Signed-off-by: Duan Jiong <duanj.fnst@cn.fujitsu.com>
---
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");
--
1.8.3.1
next reply other threads:[~2014-12-17 7:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-17 7:28 Duan Jiong [this message]
2014-12-24 20:27 ` [PATCH iproute2] ip link: use addattr_nest()/addattr_nest_end() Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=549130AD.6090407@cn.fujitsu.com \
--to=duanj.fnst@cn.fujitsu.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.