From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org, thaller@redhat.com
Subject: [patch iproute2 1/2] libnetlink: add parse_rtattr_one_nested helper
Date: Tue, 6 Jan 2015 17:23:45 +0100 [thread overview]
Message-ID: <1420561426-3118-1-git-send-email-jiri@resnulli.us> (raw)
Sometimes, it is more convenient to get only one specific nested attribute by
type. For example for IFLA_AF_SPEC where type is address family (AF_INET6).
So add this helper for this purpose.
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
include/libnetlink.h | 4 ++++
lib/libnetlink.c | 12 ++++++++++++
2 files changed, 16 insertions(+)
diff --git a/include/libnetlink.h b/include/libnetlink.h
index fe7d5d3..f0faf2d 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -80,11 +80,15 @@ extern int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int le
extern int parse_rtattr_flags(struct rtattr *tb[], int max, struct rtattr *rta,
int len, unsigned short flags);
extern int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int len);
+extern struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len);
extern int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta, int len);
#define parse_rtattr_nested(tb, max, rta) \
(parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta)))
+#define parse_rtattr_one_nested(type, rta) \
+ (parse_rtattr_one(type, RTA_DATA(rta), RTA_PAYLOAD(rta)))
+
#define parse_rtattr_nested_compat(tb, max, rta, data, len) \
({ data = RTA_PAYLOAD(rta) >= len ? RTA_DATA(rta) : NULL; \
__parse_rtattr_nested_compat(tb, max, rta, len); })
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 8d504a9..8e70263 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -701,6 +701,18 @@ int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int l
return i;
}
+struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len)
+{
+ while (RTA_OK(rta, len)) {
+ if (rta->rta_type == type)
+ return rta;
+ rta = RTA_NEXT(rta, len);
+ }
+ if (len)
+ fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", len, rta->rta_len);
+ return NULL;
+}
+
int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta,
int len)
{
--
1.9.3
next reply other threads:[~2015-01-06 16:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-06 16:23 Jiri Pirko [this message]
2015-01-06 16:23 ` [patch iproute2 2/2] iplink: print out addrgenmode attribute Jiri Pirko
2015-01-06 16:52 ` Thomas Haller
2015-01-06 17:08 ` Jiri Pirko
2015-01-07 23:10 ` Stephen Hemminger
2015-01-08 7:04 ` Jiri Pirko
2015-01-08 7:13 ` Vadim Kochan
2015-01-08 18:19 ` Stephen Hemminger
2015-01-07 23:15 ` [patch iproute2 1/2] libnetlink: add parse_rtattr_one_nested helper 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=1420561426-3118-1-git-send-email-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
--cc=thaller@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).