19 struct 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;
31 EXPORT_SYMBOL(mnl_msg_alloc);
33 void *mnl_msg_put(
struct mnl_msg *msg,
const void *data,
size_t datalen)
35 if (datalen > msg->rem)
39 memcpy(msg->tail, data, datalen);
42 EXPORT_SYMBOL(mnl_msg_put);
44 void mnl_msg_next(
struct mnl_msg *msg)
46 msg->data = msg->tail;
49 void mnl_msg_free(
struct mnl_msg *msg)
53 EXPORT_SYMBOL(mnl_msg_free);
55 void *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)
65 mnl_attr_put(nlh, type, len, data);
66 len = MNL_ALIGN(attr->nla_len);
76 void *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);
81 void *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);
86 void *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);
91 void *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);
96 void *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);
101 void *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);
106 struct 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)
115 nest = mnl_attr_nest_start(nlh, type);
118 if (attr->attr_len > nest->attr_len)
124 void mnl_msg_attr_nest_end(
struct mnl_msg *msg,
struct nlattr *start)
126 mnl_attr_nest_end((
struct nlmsghdr *)msg->data, start);