memcpy(RTA_DATA(rta), data.ptr, data.len);
hdr->nlmsg_len = NLMSG_ALIGN(hdr->nlmsg_len) + rta->rta_len;
}
+
+/**
+ * Described in header.
+ */
+void* netlink_reserve(struct nlmsghdr *hdr, int buflen, int type, int len)
+{
+ struct rtattr *rta;
+
+ if (NLMSG_ALIGN(hdr->nlmsg_len) + RTA_LENGTH(len) > buflen)
+ {
+ DBG1(DBG_KNL, "unable to add attribute, buffer too small");
+ return NULL;
+ }
+
+ rta = ((void*)hdr) + NLMSG_ALIGN(hdr->nlmsg_len);
+ rta->rta_type = type;
+ rta->rta_len = RTA_LENGTH(len);
+ hdr->nlmsg_len = NLMSG_ALIGN(hdr->nlmsg_len) + rta->rta_len;
+
+ return RTA_DATA(rta);
+}
void netlink_add_attribute(struct nlmsghdr *hdr, int rta_type, chunk_t data,
size_t buflen);
+/**
+ * Reserve space in a netlink message for given size and type, returning buffer.
+ *
+ * @param hdr netlink message
+ * @param buflen size of full netlink buffer
+ * @param type RTA type
+ * @param len length of RTA data
+ * @return buffer to len bytes of attribute data, NULL on error
+ */
+void* netlink_reserve(struct nlmsghdr *hdr, int buflen, int type, int len);
+
#endif /* KERNEL_NETLINK_SHARED_H_ */