Commit decbb437 authored by Jiri Pirko's avatar Jiri Pirko Committed by Stephen Hemminger

libnetlink: add parse_rtattr_one_nested helper

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: default avatarJiri Pirko <jiri@resnulli.us>
parent dd8fac8c
......@@ -82,11 +82,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); })
......
......@@ -713,6 +713,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)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment