2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2022 Alexander V. Chernikov <melifaro@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include "opt_netlink.h"
30 #include <sys/cdefs.h>
31 #include <sys/param.h>
32 #include <sys/malloc.h>
34 #include <sys/rmlock.h>
37 #include <sys/socket.h>
38 #include <sys/socketvar.h>
39 #include <sys/syslog.h>
41 #include <netlink/netlink.h>
42 #include <netlink/netlink_ctl.h>
43 #include <netlink/netlink_linux.h>
44 #include <netlink/netlink_var.h>
46 #define DEBUG_MOD_NAME nl_writer
47 #define DEBUG_MAX_LEVEL LOG_DEBUG3
48 #include <netlink/netlink_debug.h>
49 _DECLARE_DEBUG(LOG_INFO);
52 * The goal of this file is to provide convenient message writing KPI on top of
53 * different storage methods (mbufs, uio, temporary memory chunks).
55 * The main KPI guarantee is that the (last) message always resides in the contiguous
56 * memory buffer, so one is able to update the header after writing the entire message.
58 * This guarantee comes with a side effect of potentially reallocating underlying
59 * buffer, so one needs to update the desired pointers after something is added
62 * Messaging layer contains hooks performing transparent Linux translation for the messages.
64 * There are 3 types of supported targets:
65 * * socket (adds mbufs to the socket buffer, used for message replies)
66 * * group (sends mbuf/chain to the specified groups, used for the notifications)
67 * * chain (returns mbuf chain, used in Linux message translation code)
69 * There are 3 types of storage:
70 * * NS_WRITER_TYPE_MBUF (mbuf-based, most efficient, used when a single message
72 * * NS_WRITER_TYPE_BUF (fallback, malloc-based, used when a single message needs
73 * to be larger than one supported by NS_WRITER_TYPE_MBUF)
74 * * NS_WRITER_TYPE_LBUF (malloc-based, similar to NS_WRITER_TYPE_BUF, used for
75 * Linux sockets, calls translation hook prior to sending messages to the socket).
77 * Internally, KPI switches between different types of storage when memory requirements
78 * change. It happens transparently to the caller.
82 * Uma zone for the mbuf-based Netlink storage
84 static uma_zone_t nlmsg_zone;
87 nl_free_mbuf_storage(struct mbuf *m)
89 uma_zfree(nlmsg_zone, m->m_ext.ext_buf);
93 nl_setup_mbuf_storage(void *mem, int size, void *arg, int how __unused)
95 struct mbuf *m = (struct mbuf *)arg;
98 m_extadd(m, mem, size, nl_free_mbuf_storage, NULL, NULL, 0, EXT_MOD_TYPE);
104 nl_get_mbuf_flags(int size, int malloc_flags, int mbuf_flags)
106 struct mbuf *m, *m_storage;
109 return (m_get2(size, malloc_flags, MT_DATA, mbuf_flags));
111 if (__predict_false(size > NLMBUFSIZE))
114 m = m_gethdr(malloc_flags, MT_DATA);
118 m_storage = uma_zalloc_arg(nlmsg_zone, m, malloc_flags);
119 if (m_storage == NULL) {
128 nl_get_mbuf(int size, int malloc_flags)
130 return (nl_get_mbuf_flags(size, malloc_flags, M_PKTHDR));
134 * Gets a chain of Netlink mbufs.
135 * This is strip-down version of m_getm2()
138 nl_get_mbuf_chain(int len, int malloc_flags)
140 struct mbuf *m_chain = NULL, *m_tail = NULL;
141 int mbuf_flags = M_PKTHDR;
144 int sz = len > NLMBUFSIZE ? NLMBUFSIZE: len;
145 struct mbuf *m = nl_get_mbuf_flags(sz, malloc_flags, mbuf_flags);
159 mbuf_flags &= ~M_PKTHDR; /* Only valid on the first mbuf. */
166 nl_init_msg_zone(void)
168 nlmsg_zone = uma_zcreate("netlink", NLMBUFSIZE, nl_setup_mbuf_storage,
169 NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
173 nl_destroy_msg_zone(void)
175 uma_zdestroy(nlmsg_zone);
179 typedef bool nlwriter_op_init(struct nl_writer *nw, int size, bool waitok);
180 typedef bool nlwriter_op_write(struct nl_writer *nw, void *buf, int buflen, int cnt);
182 struct nlwriter_ops {
183 nlwriter_op_init *init;
184 nlwriter_op_write *write_socket;
185 nlwriter_op_write *write_group;
186 nlwriter_op_write *write_chain;
191 * Writes message to a temporary memory buffer,
192 * flushing to the socket/group when buffer size limit is reached
195 nlmsg_get_ns_buf(struct nl_writer *nw, int size, bool waitok)
197 int mflag = waitok ? M_WAITOK : M_NOWAIT;
198 nw->_storage = malloc(size, M_NETLINK, mflag | M_ZERO);
199 if (__predict_false(nw->_storage == NULL))
201 nw->alloc_len = size;
204 nw->data = nw->_storage;
205 nw->writer_type = NS_WRITER_TYPE_BUF;
206 nw->malloc_flag = mflag;
207 nw->num_messages = 0;
213 nlmsg_write_socket_buf(struct nl_writer *nw, void *buf, int datalen, int cnt)
215 NL_LOG(LOG_DEBUG2, "IN: ptr: %p len: %d arg: %p", buf, datalen, nw->arg.ptr);
216 if (__predict_false(datalen == 0)) {
217 free(buf, M_NETLINK);
221 struct mbuf *m = nl_get_mbuf_chain(datalen, nw->malloc_flag);
222 if (__predict_false(m == NULL)) {
223 /* XXX: should we set sorcverr? */
224 free(buf, M_NETLINK);
227 m_append(m, datalen, buf);
228 free(buf, M_NETLINK);
230 int io_flags = (nw->ignore_limit) ? NL_IOF_IGNORE_LIMIT : 0;
231 return (nl_send_one(m, (struct nlpcb *)(nw->arg.ptr), cnt, io_flags));
235 nlmsg_write_group_buf(struct nl_writer *nw, void *buf, int datalen, int cnt)
237 NL_LOG(LOG_DEBUG2, "IN: ptr: %p len: %d proto: %d id: %d", buf, datalen,
238 nw->arg.group.proto, nw->arg.group.id);
239 if (__predict_false(datalen == 0)) {
240 free(buf, M_NETLINK);
244 struct mbuf *m = nl_get_mbuf_chain(datalen, nw->malloc_flag);
245 if (__predict_false(m == NULL)) {
246 free(buf, M_NETLINK);
249 bool success = m_append(m, datalen, buf) != 0;
250 free(buf, M_NETLINK);
255 nl_send_group(m, cnt, nw->arg.group.proto, nw->arg.group.id);
260 nlmsg_write_chain_buf(struct nl_writer *nw, void *buf, int datalen, int cnt)
262 struct mbuf **m0 = (struct mbuf **)(nw->arg.ptr);
263 NL_LOG(LOG_DEBUG2, "IN: ptr: %p len: %d arg: %p", buf, datalen, nw->arg.ptr);
265 if (__predict_false(datalen == 0)) {
266 free(buf, M_NETLINK);
271 struct mbuf *m = nl_get_mbuf_chain(datalen, nw->malloc_flag);
273 if (__predict_false(m == NULL)) {
274 free(buf, M_NETLINK);
279 if (__predict_false(m_append(*m0, datalen, buf) == 0)) {
280 free(buf, M_NETLINK);
288 * NS_WRITER_TYPE_MBUF
289 * Writes message to the allocated mbuf,
290 * flushing to socket/group when mbuf size limit is reached.
291 * This is the most efficient mechanism as it avoids double-copying.
293 * Allocates a single mbuf suitable to store up to @size bytes of data.
294 * If size < MHLEN (around 160 bytes), allocates mbuf with pkghdr.
295 * If the size <= NLMBUFSIZE (2k), allocate mbuf+storage out of nlmsg_zone.
296 * Returns NULL on greater size or the allocation failure.
299 nlmsg_get_ns_mbuf(struct nl_writer *nw, int size, bool waitok)
301 int mflag = waitok ? M_WAITOK : M_NOWAIT;
302 struct mbuf *m = nl_get_mbuf(size, mflag);
304 if (__predict_false(m == NULL))
306 nw->alloc_len = M_TRAILINGSPACE(m);
309 nw->_storage = (void *)m;
310 nw->data = mtod(m, void *);
311 nw->writer_type = NS_WRITER_TYPE_MBUF;
312 nw->malloc_flag = mflag;
313 nw->num_messages = 0;
315 memset(nw->data, 0, size);
316 NL_LOG(LOG_DEBUG2, "alloc mbuf %p req_len %d alloc_len %d data_ptr %p",
317 m, size, nw->alloc_len, nw->data);
322 nlmsg_write_socket_mbuf(struct nl_writer *nw, void *buf, int datalen, int cnt)
324 struct mbuf *m = (struct mbuf *)buf;
325 NL_LOG(LOG_DEBUG2, "IN: ptr: %p len: %d arg: %p", buf, datalen, nw->arg.ptr);
327 if (__predict_false(datalen == 0)) {
332 m->m_pkthdr.len = datalen;
334 int io_flags = (nw->ignore_limit) ? NL_IOF_IGNORE_LIMIT : 0;
335 return (nl_send_one(m, (struct nlpcb *)(nw->arg.ptr), cnt, io_flags));
339 nlmsg_write_group_mbuf(struct nl_writer *nw, void *buf, int datalen, int cnt)
341 struct mbuf *m = (struct mbuf *)buf;
342 NL_LOG(LOG_DEBUG2, "IN: ptr: %p len: %d proto: %d id: %d", buf, datalen,
343 nw->arg.group.proto, nw->arg.group.id);
345 if (__predict_false(datalen == 0)) {
350 m->m_pkthdr.len = datalen;
352 nl_send_group(m, cnt, nw->arg.group.proto, nw->arg.group.id);
357 nlmsg_write_chain_mbuf(struct nl_writer *nw, void *buf, int datalen, int cnt)
359 struct mbuf *m_new = (struct mbuf *)buf;
360 struct mbuf **m0 = (struct mbuf **)(nw->arg.ptr);
362 NL_LOG(LOG_DEBUG2, "IN: ptr: %p len: %d arg: %p", buf, datalen, nw->arg.ptr);
364 if (__predict_false(datalen == 0)) {
369 m_new->m_pkthdr.len = datalen;
370 m_new->m_len = datalen;
376 for (m_last = *m0; m_last->m_next != NULL; m_last = m_last->m_next)
378 m_last->m_next = m_new;
379 (*m0)->m_pkthdr.len += datalen;
386 * NS_WRITER_TYPE_LBUF
387 * Writes message to the allocated memory buffer,
388 * flushing to socket/group when mbuf size limit is reached.
389 * Calls linux handler to rewrite messages before sending to the socket.
392 nlmsg_get_ns_lbuf(struct nl_writer *nw, int size, bool waitok)
394 int mflag = waitok ? M_WAITOK : M_NOWAIT;
395 size = roundup2(size, sizeof(void *));
396 int add_size = sizeof(struct linear_buffer) + SCRATCH_BUFFER_SIZE;
397 char *buf = malloc(add_size + size * 2, M_NETLINK, mflag | M_ZERO);
398 if (__predict_false(buf == NULL))
401 /* Fill buffer header first */
402 struct linear_buffer *lb = (struct linear_buffer *)buf;
403 lb->base = &buf[sizeof(struct linear_buffer) + size];
404 lb->size = size + SCRATCH_BUFFER_SIZE;
406 nw->alloc_len = size;
410 nw->data = (char *)(lb + 1);
411 nw->malloc_flag = mflag;
412 nw->writer_type = NS_WRITER_TYPE_LBUF;
413 nw->num_messages = 0;
419 nlmsg_write_socket_lbuf(struct nl_writer *nw, void *buf, int datalen, int cnt)
421 struct linear_buffer *lb = (struct linear_buffer *)buf;
422 char *data = (char *)(lb + 1);
423 struct nlpcb *nlp = (struct nlpcb *)(nw->arg.ptr);
425 if (__predict_false(datalen == 0)) {
426 free(buf, M_NETLINK);
430 struct mbuf *m = NULL;
431 if (linux_netlink_p != NULL)
432 m = linux_netlink_p->msgs_to_linux(nlp->nl_proto, data, datalen, nlp);
433 free(buf, M_NETLINK);
435 if (__predict_false(m == NULL)) {
436 /* XXX: should we set sorcverr? */
440 int io_flags = (nw->ignore_limit) ? NL_IOF_IGNORE_LIMIT : 0;
441 return (nl_send_one(m, nlp, cnt, io_flags));
444 /* Shouldn't be called (maybe except Linux code originating message) */
446 nlmsg_write_group_lbuf(struct nl_writer *nw, void *buf, int datalen, int cnt)
448 struct linear_buffer *lb = (struct linear_buffer *)buf;
449 char *data = (char *)(lb + 1);
451 if (__predict_false(datalen == 0)) {
452 free(buf, M_NETLINK);
456 struct mbuf *m = nl_get_mbuf_chain(datalen, nw->malloc_flag);
457 if (__predict_false(m == NULL)) {
458 free(buf, M_NETLINK);
461 m_append(m, datalen, data);
462 free(buf, M_NETLINK);
464 nl_send_group(m, cnt, nw->arg.group.proto, nw->arg.group.id);
468 static const struct nlwriter_ops nlmsg_writers[] = {
469 /* NS_WRITER_TYPE_MBUF */
471 .init = nlmsg_get_ns_mbuf,
472 .write_socket = nlmsg_write_socket_mbuf,
473 .write_group = nlmsg_write_group_mbuf,
474 .write_chain = nlmsg_write_chain_mbuf,
476 /* NS_WRITER_TYPE_BUF */
478 .init = nlmsg_get_ns_buf,
479 .write_socket = nlmsg_write_socket_buf,
480 .write_group = nlmsg_write_group_buf,
481 .write_chain = nlmsg_write_chain_buf,
483 /* NS_WRITER_TYPE_LBUF */
485 .init = nlmsg_get_ns_lbuf,
486 .write_socket = nlmsg_write_socket_lbuf,
487 .write_group = nlmsg_write_group_lbuf,
492 nlmsg_set_callback(struct nl_writer *nw)
494 const struct nlwriter_ops *pops = &nlmsg_writers[nw->writer_type];
496 switch (nw->writer_target) {
497 case NS_WRITER_TARGET_SOCKET:
498 nw->cb = pops->write_socket;
500 case NS_WRITER_TARGET_GROUP:
501 nw->cb = pops->write_group;
503 case NS_WRITER_TARGET_CHAIN:
504 nw->cb = pops->write_chain;
507 panic("not implemented");
512 nlmsg_get_buf_type(struct nl_writer *nw, int size, int type, bool waitok)
514 MPASS(type + 1 <= sizeof(nlmsg_writers) / sizeof(nlmsg_writers[0]));
515 NL_LOG(LOG_DEBUG3, "Setting up nw %p size %d type %d", nw, size, type);
516 return (nlmsg_writers[type].init(nw, size, waitok));
520 nlmsg_get_buf(struct nl_writer *nw, int size, bool waitok, bool is_linux)
525 if (__predict_true(size <= NLMBUFSIZE))
526 type = NS_WRITER_TYPE_MBUF;
528 type = NS_WRITER_TYPE_BUF;
530 type = NS_WRITER_TYPE_LBUF;
531 return (nlmsg_get_buf_type(nw, size, type, waitok));
535 _nlmsg_get_unicast_writer(struct nl_writer *nw, int size, struct nlpcb *nlp)
537 if (!nlmsg_get_buf(nw, size, false, nlp->nl_linux))
539 nw->arg.ptr = (void *)nlp;
540 nw->writer_target = NS_WRITER_TARGET_SOCKET;
541 nlmsg_set_callback(nw);
546 _nlmsg_get_group_writer(struct nl_writer *nw, int size, int protocol, int group_id)
548 if (!nlmsg_get_buf(nw, size, false, false))
550 nw->arg.group.proto = protocol;
551 nw->arg.group.id = group_id;
552 nw->writer_target = NS_WRITER_TARGET_GROUP;
553 nlmsg_set_callback(nw);
558 _nlmsg_get_chain_writer(struct nl_writer *nw, int size, struct mbuf **pm)
560 if (!nlmsg_get_buf(nw, size, false, false))
563 nw->arg.ptr = (void *)pm;
564 nw->writer_target = NS_WRITER_TARGET_CHAIN;
565 nlmsg_set_callback(nw);
566 NL_LOG(LOG_DEBUG3, "setup cb %p (need %p)", nw->cb, &nlmsg_write_chain_mbuf);
571 _nlmsg_ignore_limit(struct nl_writer *nw)
573 nw->ignore_limit = true;
577 _nlmsg_flush(struct nl_writer *nw)
580 if (__predict_false(nw->hdr != NULL)) {
581 /* Last message has not been completed, skip it. */
582 int completed_len = (char *)nw->hdr - nw->data;
583 /* Send completed messages */
584 nw->offset -= nw->offset - completed_len;
588 NL_LOG(LOG_DEBUG2, "OUT");
589 bool result = nw->cb(nw, nw->_storage, nw->offset, nw->num_messages);
593 NL_LOG(LOG_DEBUG, "nw %p offset %d: flush with %p() failed", nw, nw->offset, nw->cb);
600 * Flushes previous data and allocates new underlying storage
601 * sufficient for holding at least @required_len bytes.
602 * Return true on success.
605 _nlmsg_refill_buffer(struct nl_writer *nw, int required_len)
607 struct nl_writer ns_new = {};
608 int completed_len, new_len;
613 NL_LOG(LOG_DEBUG3, "no space at offset %d/%d (want %d), trying to reclaim",
614 nw->offset, nw->alloc_len, required_len);
616 /* Calculated new buffer size and allocate it s*/
617 completed_len = (nw->hdr != NULL) ? (char *)nw->hdr - nw->data : nw->offset;
618 if (completed_len > 0 && required_len < NLMBUFSIZE) {
619 /* We already ran out of space, use the largest effective size */
620 new_len = max(nw->alloc_len, NLMBUFSIZE);
622 if (nw->alloc_len < NLMBUFSIZE)
623 new_len = NLMBUFSIZE;
625 new_len = nw->alloc_len * 2;
626 while (new_len < required_len)
629 bool waitok = (nw->malloc_flag == M_WAITOK);
630 bool is_linux = (nw->writer_type == NS_WRITER_TYPE_LBUF);
631 if (!nlmsg_get_buf(&ns_new, new_len, waitok, is_linux)) {
633 NL_LOG(LOG_DEBUG, "getting new buf failed, setting ENOMEM");
636 if (nw->ignore_limit)
637 nlmsg_ignore_limit(&ns_new);
639 /* Update callback data */
640 ns_new.writer_target = nw->writer_target;
641 nlmsg_set_callback(&ns_new);
642 ns_new.arg = nw->arg;
644 /* Copy last (unfinished) header to the new storage */
645 int last_len = nw->offset - completed_len;
647 memcpy(ns_new.data, nw->hdr, last_len);
648 ns_new.hdr = (struct nlmsghdr *)ns_new.data;
649 ns_new.offset = last_len;
652 NL_LOG(LOG_DEBUG2, "completed: %d bytes, copied: %d bytes", completed_len, last_len);
654 /* Flush completed headers & switch to the new nw */
656 memcpy(nw, &ns_new, sizeof(struct nl_writer));
657 NL_LOG(LOG_DEBUG2, "switched buffer: used %d/%d bytes", nw->offset, nw->alloc_len);
663 _nlmsg_add(struct nl_writer *nw, uint32_t portid, uint32_t seq, uint16_t type,
664 uint16_t flags, uint32_t len)
666 struct nlmsghdr *hdr;
668 MPASS(nw->hdr == NULL);
670 int required_len = NETLINK_ALIGN(len + sizeof(struct nlmsghdr));
671 if (__predict_false(nw->offset + required_len > nw->alloc_len)) {
672 if (!nlmsg_refill_buffer(nw, required_len))
676 hdr = (struct nlmsghdr *)(&nw->data[nw->offset]);
678 hdr->nlmsg_len = len;
679 hdr->nlmsg_type = type;
680 hdr->nlmsg_flags = flags;
681 hdr->nlmsg_seq = seq;
682 hdr->nlmsg_pid = portid;
685 nw->offset += sizeof(struct nlmsghdr);
691 _nlmsg_end(struct nl_writer *nw)
693 MPASS(nw->hdr != NULL);
696 NL_LOG(LOG_DEBUG, "ENOMEM when dumping message");
701 nw->hdr->nlmsg_len = (uint32_t)(nw->data + nw->offset - (char *)nw->hdr);
702 NL_LOG(LOG_DEBUG2, "wrote msg len: %u type: %d: flags: 0x%X seq: %u pid: %u",
703 nw->hdr->nlmsg_len, nw->hdr->nlmsg_type, nw->hdr->nlmsg_flags,
704 nw->hdr->nlmsg_seq, nw->hdr->nlmsg_pid);
711 _nlmsg_abort(struct nl_writer *nw)
713 if (nw->hdr != NULL) {
714 nw->offset = (uint32_t)((char *)nw->hdr - nw->data);
720 nlmsg_ack(struct nlpcb *nlp, int error, struct nlmsghdr *hdr,
721 struct nl_pstate *npt)
723 struct nlmsgerr *errmsg;
725 uint32_t flags = nlp->nl_flags;
726 struct nl_writer *nw = npt->nw;
729 payload_len = sizeof(struct nlmsgerr);
732 * The only case when we send the full message in the
733 * reply is when there is an error and NETLINK_CAP_ACK
736 cap_ack = (error == 0) || (flags & NLF_CAP_ACK);
738 payload_len += hdr->nlmsg_len - sizeof(struct nlmsghdr);
739 payload_len = NETLINK_ALIGN(payload_len);
741 uint16_t nl_flags = cap_ack ? NLM_F_CAPPED : 0;
742 if ((npt->err_msg || npt->err_off) && nlp->nl_flags & NLF_EXT_ACK)
743 nl_flags |= NLM_F_ACK_TLVS;
745 NL_LOG(LOG_DEBUG3, "acknowledging message type %d seq %d",
746 hdr->nlmsg_type, hdr->nlmsg_seq);
748 if (!nlmsg_add(nw, nlp->nl_port, hdr->nlmsg_seq, NLMSG_ERROR, nl_flags, payload_len))
751 errmsg = nlmsg_reserve_data(nw, payload_len, struct nlmsgerr);
752 errmsg->error = error;
753 /* In case of error copy the whole message, else just the header */
754 memcpy(&errmsg->msg, hdr, cap_ack ? sizeof(*hdr) : hdr->nlmsg_len);
756 if (npt->err_msg != NULL && nlp->nl_flags & NLF_EXT_ACK)
757 nlattr_add_string(nw, NLMSGERR_ATTR_MSG, npt->err_msg);
758 if (npt->err_off != 0 && nlp->nl_flags & NLF_EXT_ACK)
759 nlattr_add_u32(nw, NLMSGERR_ATTR_OFFS, npt->err_off);
760 if (npt->cookie != NULL)
761 nlattr_add_raw(nw, npt->cookie);
766 NLP_LOG(LOG_DEBUG, nlp, "error allocating ack data for message %d seq %u",
767 hdr->nlmsg_type, hdr->nlmsg_seq);
772 _nlmsg_end_dump(struct nl_writer *nw, int error, struct nlmsghdr *hdr)
774 if (!nlmsg_add(nw, hdr->nlmsg_pid, hdr->nlmsg_seq, NLMSG_DONE, 0, sizeof(int))) {
775 NL_LOG(LOG_DEBUG, "Error finalizing table dump");
778 /* Save operation result */
779 int *perror = nlmsg_reserve_object(nw, int);
780 NL_LOG(LOG_DEBUG2, "record error=%d at off %d (%p)", error,
784 nw->suppress_ack = true;
789 #include <netlink/ktest_netlink_message_writer.h>