-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnl.h
61 lines (47 loc) · 1.25 KB
/
nl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* SPDX-License-Identifier: MIT */
/*
* Author: Jianhui Zhao <[email protected]>
*/
#ifndef __ECO_NL_H
#define __ECO_NL_H
#include <linux/netlink.h>
#include <errno.h>
#include "eco.h"
#define ECO_NLMSG_KER_MT "eco{nlmsg-kernel}"
struct eco_nlmsg {
struct nlmsghdr *nlh;
struct nlattr *nest;
int size;
uint8_t buf[0];
};
static inline int nla_type(const struct nlattr *nla)
{
return nla->nla_type & NLA_TYPE_MASK;
}
static inline void *nla_data(const struct nlattr *nla)
{
return (char *)nla + NLA_HDRLEN;
}
static inline int nla_len(const struct nlattr *nla)
{
return nla->nla_len - NLA_HDRLEN;
}
static inline int nla_ok(const struct nlattr *nla, int remaining)
{
return remaining >= (int) sizeof(*nla) &&
nla->nla_len >= sizeof(*nla) &&
nla->nla_len <= remaining;
}
static inline struct nlattr *nla_next(const struct nlattr *nla, int *remaining)
{
unsigned int totlen = NLA_ALIGN(nla->nla_len);
*remaining -= totlen;
return (struct nlattr *)((char *) nla + totlen);
}
#define nla_for_each_attr(pos, head, len, rem) \
for (pos = head, rem = len; \
nla_ok(pos, rem); \
pos = nla_next(pos, &(rem)))
#define nla_for_each_nested(pos, nla, rem) \
nla_for_each_attr(pos, nla_data(nla), nla_len(nla), rem)
#endif