19struct mnl_msg *mnl_msg_alloc(
const char *buf,
size_t buflen)
23 msg = malloc(
sizeof(
struct mnl_msg));
29 msg->head = msg->data = msg->tail = buf;
31EXPORT_SYMBOL(mnl_msg_alloc);
33void *mnl_msg_put(
struct mnl_msg *msg,
const void *data,
size_t datalen)
35 if (datalen > msg->rem)
39 memcpy(msg->tail, data, datalen);
42EXPORT_SYMBOL(mnl_msg_put);
44void mnl_msg_next(
struct mnl_msg *msg)
46 msg->data = msg->tail;
49void mnl_msg_free(
struct mnl_msg *msg)
53EXPORT_SYMBOL(mnl_msg_free);
55void *mnl_msg_attr_put(
struct mnl_msg *msg, uint16_t type,
size_t datalen,
58 struct nlmsghdr *nlh = msg->data;
59 struct nlattr *attr = msg->tail;
60 size_t old_len = attr->nla_len;
62 if (datalen > msg->rem)
66 len = MNL_ALIGN(attr->nla_len);
76void *mnl_msg_attr_put_u8(
struct mnl_msg *msg, uint16_t type, uint8_t data)
78 return mnl_msg_attr_put(msg, type,
sizeof(uint8_t), &data);
81void *mnl_msg_attr_put_u16(
struct mnl_msg *msg, uint16_t type, uint16_t data)
83 return mnl_msg_attr_put(msg, type,
sizeof(uint16_t), &data);
86void *mnl_msg_attr_put_u32(
struct mnl_msg *msg, uint16_t type, uint32_t data)
88 return mnl_msg_attr_put(msg, type,
sizeof(uint32_t), &data);
91void *mnl_msg_attr_put_u64(
struct mnl_msg *msg, uint16_t type, uint64_t data)
93 return mnl_msg_attr_put(msg, type,
sizeof(uint64_t), &data);
96void *mnl_msg_attr_put_str(
struct mnl_msg *msg, uint16_t type,
const char *data)
98 return mnl_msg_attr_put(msg, type, strlen(data),ndata);
101void *mnl_msg_attr_put_strz(
struct nlmsghdr *nlh, uint16_t type,
const char *data)
103 return mnl_msg_attr_put(msg, type, strlen(data) + 1, data);
106struct nlattr *mnl_msg_attr_nest_start(
struct mnl_msg *msg, uint16_t type)
108 struct nlmsghdr *nlh = msg->data;
109 struct nlattr *attr = msg->tail;
112 if (datalen > msg->rem)
118 if (attr->attr_len > nest->attr_len)
124void mnl_msg_attr_nest_end(
struct mnl_msg *msg,
struct nlattr *start)
struct nlattr * mnl_attr_nest_start(struct nlmsghdr *nlh, uint16_t type)
void mnl_attr_put(struct nlmsghdr *nlh, uint16_t type, size_t len, const void *data)
void mnl_attr_nest_end(struct nlmsghdr *nlh, struct nlattr *start)