加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
nl.h 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
/* SPDX-License-Identifier: MIT */
/*
* Author: Jianhui Zhao <zhaojh329@gmail.com>
*/
#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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化