diff options
| author | Ishan Agrawal <iagrawal9990@gmail.com> | 2026-06-28 04:14:28 +0000 |
|---|---|---|
| committer | Kristof Provost <kp@FreeBSD.org> | 2026-07-03 08:20:12 +0000 |
| commit | c9d98c0134864d8bc69006b92d34a3b22c940870 (patch) | |
| tree | dc476c698d7998870506b4ff677b1bafb0ddf431 | |
| parent | c041b82c59e885d106f45454302bad3d9dcc58a7 (diff) | |
netlink: add const variants of NLA iteration macros
Add const-qualified versions of the NLA iteration helpers to allow
walking immutable netlink attribute buffers without discarding const
qualifiers.
This introduces NLA_NEXT_CONST(), _NLA_END_CONST(), and
NLA_FOREACH_CONST() in netlink_snl.h.
Signed-off-by: Ishan Agrawal <iagrawal9990@gmail.com>
Sponsored-by : Google LLC (GSoC 2026)
| -rw-r--r-- | sys/netlink/netlink_snl.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/sys/netlink/netlink_snl.h b/sys/netlink/netlink_snl.h index 52b35e502c98..34a0f3791af2 100644 --- a/sys/netlink/netlink_snl.h +++ b/sys/netlink/netlink_snl.h @@ -69,6 +69,18 @@ ((char *)NLA_NEXT(_attr) <= _NLA_END(_start, _len)); \ _attr = NLA_NEXT(_attr)) +#define NLA_NEXT_CONST(_attr) (const struct nlattr *)(const void *) \ + ((const char *)_attr + NLA_ALIGN(_attr->nla_len)) + +#define _NLA_END_CONST(_start, _len) \ + ((const char *)(_start) + (_len)) +#define NLA_FOREACH_CONST(_attr, _start, _len) \ + for (_attr = (const struct nlattr *)(_start); \ + ((const char *)_attr < _NLA_END_CONST(_start, _len)) && \ + ((const char *)NLA_NEXT_CONST(_attr) <= \ + _NLA_END_CONST(_start, _len)); \ + _attr = NLA_NEXT_CONST(_attr)) + struct linear_buffer { char *base; /* Base allocated memory pointer */ uint32_t offset; /* Currently used offset */ |
