Thread (29 messages) 29 messages, 6 authors, 2021-04-22

Re: [PATCH bpf-next v3 1/3] libbpf: add helpers for preparing netlink attributes

From: Yonghong Song <hidden>
Date: 2021-04-21 06:38:15
Also in: bpf


On 4/20/21 12:37 PM, Kumar Kartikeya Dwivedi wrote:
This change introduces a few helpers to wrap open coded attribute
preparation in netlink.c.

Every nested attribute's closure must happen using the helper
nlattr_end_nested, which sets its length properly. NLA_F_NESTED is
enforeced using nlattr_begin_nested helper. Other simple attributes
typo: enforced
can be added directly.

The maxsz parameter corresponds to the size of the request structure
which is being filled in, so for instance with req being:

struct {
	struct nlmsghdr nh;
	struct tcmsg t;
	char buf[4096];
} req;

Then, maxsz should be sizeof(req).

This change also converts the open coded attribute preparation with the
helpers. Note that the only failure the internal call to nlattr_add
could result in the nested helper would be -EMSGSIZE, hence that is what
we return to our caller.

Reviewed-by: Toke Høiland-Jørgensen <redacted>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
  tools/lib/bpf/netlink.c | 37 ++++++++++++++-----------------
  tools/lib/bpf/nlattr.h  | 48 +++++++++++++++++++++++++++++++++++++++++
  2 files changed, 64 insertions(+), 21 deletions(-)
[...]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help