Commit 303cc9cb authored by Roopa Prabhu's avatar Roopa Prabhu Committed by Stephen Hemminger

libnetlink: introduce rta_nest and u8, u16, u64 helpers for nesting within rtattr

This patch introduces two new api's rta_nest and rta_nest_end to
nest attributes inside a rta attribute represented by 'struct rtattr'
as required to construct a nexthop. Also adds rta_addattr* variants
for u8, u16 and u64 as needed to support encapsulation.
Signed-off-by: default avatarRoopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: default avatarThomas Graf <tgraf@suug.ch>
Acked-by: default avatarJiri Benc <jbenc@redhat.com>
parent 0ee9052f
...@@ -86,7 +86,10 @@ int addattr_nest_end(struct nlmsghdr *n, struct rtattr *nest); ...@@ -86,7 +86,10 @@ int addattr_nest_end(struct nlmsghdr *n, struct rtattr *nest);
struct rtattr *addattr_nest_compat(struct nlmsghdr *n, int maxlen, int type, struct rtattr *addattr_nest_compat(struct nlmsghdr *n, int maxlen, int type,
const void *data, int len); const void *data, int len);
int addattr_nest_compat_end(struct nlmsghdr *n, struct rtattr *nest); int addattr_nest_compat_end(struct nlmsghdr *n, struct rtattr *nest);
int rta_addattr8(struct rtattr *rta, int maxlen, int type, __u8 data);
int rta_addattr16(struct rtattr *rta, int maxlen, int type, __u16 data);
int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data); int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data);
int rta_addattr64(struct rtattr *rta, int maxlen, int type, __u64 data);
int rta_addattr_l(struct rtattr *rta, int maxlen, int type, int rta_addattr_l(struct rtattr *rta, int maxlen, int type,
const void *data, int alen); const void *data, int alen);
...@@ -98,6 +101,13 @@ int parse_rtattr_byindex(struct rtattr *tb[], int max, ...@@ -98,6 +101,13 @@ int parse_rtattr_byindex(struct rtattr *tb[], int max,
struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len); struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len);
int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta, int len); int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta, int len);
struct rtattr *rta_nest(struct rtattr *rta, int maxlen, int type);
int rta_nest_end(struct rtattr *rta, struct rtattr *nest);
#define RTA_TAIL(rta) \
((struct rtattr *) (((void *) (rta)) + \
RTA_ALIGN((rta)->rta_len)))
#define parse_rtattr_nested(tb, max, rta) \ #define parse_rtattr_nested(tb, max, rta) \
(parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta))) (parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta)))
......
...@@ -721,6 +721,37 @@ int rta_addattr_l(struct rtattr *rta, int maxlen, int type, ...@@ -721,6 +721,37 @@ int rta_addattr_l(struct rtattr *rta, int maxlen, int type,
return 0; return 0;
} }
int rta_addattr8(struct rtattr *rta, int maxlen, int type, __u8 data)
{
return rta_addattr_l(rta, maxlen, type, &data, sizeof(__u8));
}
int rta_addattr16(struct rtattr *rta, int maxlen, int type, __u16 data)
{
return rta_addattr_l(rta, maxlen, type, &data, sizeof(__u16));
}
int rta_addattr64(struct rtattr *rta, int maxlen, int type, __u64 data)
{
return rta_addattr_l(rta, maxlen, type, &data, sizeof(__u64));
}
struct rtattr *rta_nest(struct rtattr *rta, int maxlen, int type)
{
struct rtattr *nest = RTA_TAIL(rta);
rta_addattr_l(rta, maxlen, type, NULL, 0);
return nest;
}
int rta_nest_end(struct rtattr *rta, struct rtattr *nest)
{
nest->rta_len = (void *)RTA_TAIL(rta) - (void *)nest;
return rta->rta_len;
}
int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len)
{ {
return parse_rtattr_flags(tb, max, rta, len, 0); return parse_rtattr_flags(tb, max, rta, len, 0);
......
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