2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2009-2013 The FreeBSD Foundation
5 * Copyright (c) 2013-2015 Mariusz Zaborski <oshogbo@FreeBSD.org>
8 * This software was developed by Pawel Jakub Dawidek under sponsorship from
9 * the FreeBSD Foundation.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/endian.h>
38 #include <sys/queue.h>
42 #include <sys/errno.h>
43 #include <sys/kernel.h>
45 #include <sys/malloc.h>
46 #include <sys/systm.h>
48 #include <machine/stdarg.h>
51 #include <sys/socket.h>
72 #include "nvlist_impl.h"
73 #include "nvpair_impl.h"
77 #define PJDLOG_ASSERT(...) MPASS(__VA_ARGS__)
78 #define PJDLOG_RASSERT(expr, ...) KASSERT(expr, (__VA_ARGS__))
79 #define PJDLOG_ABORT(...) panic(__VA_ARGS__)
82 #define PJDLOG_ASSERT(...) assert(__VA_ARGS__)
83 #define PJDLOG_RASSERT(expr, ...) assert(expr)
84 #define PJDLOG_ABORT(...) do { \
85 fprintf(stderr, "%s:%u: ", __FILE__, __LINE__); \
86 fprintf(stderr, __VA_ARGS__); \
87 fprintf(stderr, "\n"); \
93 #define NV_FLAG_PRIVATE_MASK (NV_FLAG_BIG_ENDIAN | NV_FLAG_IN_ARRAY)
94 #define NV_FLAG_PUBLIC_MASK (NV_FLAG_IGNORE_CASE | NV_FLAG_NO_UNIQUE)
95 #define NV_FLAG_ALL_MASK (NV_FLAG_PRIVATE_MASK | NV_FLAG_PUBLIC_MASK)
97 #define NVLIST_MAGIC 0x6e766c /* "nvl" */
102 nvpair_t *nvl_parent;
103 nvpair_t *nvl_array_next;
104 struct nvl_head nvl_head;
107 #define NVLIST_ASSERT(nvl) do { \
108 PJDLOG_ASSERT((nvl) != NULL); \
109 PJDLOG_ASSERT((nvl)->nvl_magic == NVLIST_MAGIC); \
113 MALLOC_DEFINE(M_NVLIST, "nvlist", "kernel nvlist");
116 #define NVPAIR_ASSERT(nvp) nvpair_assert(nvp)
118 #define NVLIST_HEADER_MAGIC 0x6c
119 #define NVLIST_HEADER_VERSION 0x00
120 struct nvlist_header {
122 uint8_t nvlh_version;
124 uint64_t nvlh_descriptors;
129 nvlist_create(int flags)
133 PJDLOG_ASSERT((flags & ~(NV_FLAG_PUBLIC_MASK)) == 0);
135 nvl = nv_malloc(sizeof(*nvl));
139 nvl->nvl_flags = flags;
140 nvl->nvl_parent = NULL;
141 nvl->nvl_array_next = NULL;
142 TAILQ_INIT(&nvl->nvl_head);
143 nvl->nvl_magic = NVLIST_MAGIC;
149 nvlist_destroy(nvlist_t *nvl)
160 while ((nvp = nvlist_first_nvpair(nvl)) != NULL) {
161 nvlist_remove_nvpair(nvl, nvp);
164 if (nvl->nvl_array_next != NULL)
165 nvpair_free_structure(nvl->nvl_array_next);
166 nvl->nvl_array_next = NULL;
167 nvl->nvl_parent = NULL;
175 nvlist_set_error(nvlist_t *nvl, int error)
178 PJDLOG_ASSERT(error != 0);
181 * Check for error != 0 so that we don't do the wrong thing if somebody
182 * tries to abuse this API when asserts are disabled.
184 if (nvl != NULL && error != 0 && nvl->nvl_error == 0)
185 nvl->nvl_error = error;
189 nvlist_error(const nvlist_t *nvl)
197 return (nvl->nvl_error);
201 nvlist_get_nvpair_parent(const nvlist_t *nvl)
206 return (nvl->nvl_parent);
210 nvlist_get_parent(const nvlist_t *nvl, void **cookiep)
216 nvp = nvl->nvl_parent;
222 return (nvpair_nvlist(nvp));
226 nvlist_set_parent(nvlist_t *nvl, nvpair_t *parent)
231 nvl->nvl_parent = parent;
235 nvlist_set_array_next(nvlist_t *nvl, nvpair_t *ele)
241 nvl->nvl_flags |= NV_FLAG_IN_ARRAY;
243 nvl->nvl_flags &= ~NV_FLAG_IN_ARRAY;
244 nv_free(nvl->nvl_array_next);
247 nvl->nvl_array_next = ele;
251 nvlist_get_array_next_nvpair(nvlist_t *nvl)
256 return (nvl->nvl_array_next);
260 nvlist_in_array(const nvlist_t *nvl)
265 return ((nvl->nvl_flags & NV_FLAG_IN_ARRAY) != 0);
269 nvlist_get_array_next(const nvlist_t *nvl)
275 nvp = nvl->nvl_array_next;
279 return (nvpair_get_nvlist(nvp));
283 nvlist_get_pararr(const nvlist_t *nvl, void **cookiep)
287 ret = nvlist_get_array_next(nvl);
294 return (nvlist_get_parent(nvl, cookiep));
298 nvlist_empty(const nvlist_t *nvl)
302 PJDLOG_ASSERT(nvl->nvl_error == 0);
304 return (nvlist_first_nvpair(nvl) == NULL);
308 nvlist_flags(const nvlist_t *nvl)
312 PJDLOG_ASSERT(nvl->nvl_error == 0);
314 return (nvl->nvl_flags & NV_FLAG_PUBLIC_MASK);
318 nvlist_set_flags(nvlist_t *nvl, int flags)
322 PJDLOG_ASSERT(nvl->nvl_error == 0);
324 nvl->nvl_flags = flags;
328 nvlist_report_missing(int type, const char *name)
331 PJDLOG_ABORT("Element '%s' of type %s doesn't exist.",
332 name, nvpair_type_string(type));
336 nvlist_find(const nvlist_t *nvl, int type, const char *name)
341 PJDLOG_ASSERT(nvl->nvl_error == 0);
342 PJDLOG_ASSERT(type == NV_TYPE_NONE ||
343 (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST));
345 for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
346 nvp = nvlist_next_nvpair(nvl, nvp)) {
347 if (type != NV_TYPE_NONE && nvpair_type(nvp) != type)
349 if ((nvl->nvl_flags & NV_FLAG_IGNORE_CASE) != 0) {
350 if (strcasecmp(nvpair_name(nvp), name) != 0)
353 if (strcmp(nvpair_name(nvp), name) != 0)
366 nvlist_exists_type(const nvlist_t *nvl, const char *name, int type)
370 PJDLOG_ASSERT(nvl->nvl_error == 0);
371 PJDLOG_ASSERT(type == NV_TYPE_NONE ||
372 (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST));
374 return (nvlist_find(nvl, type, name) != NULL);
378 nvlist_free_type(nvlist_t *nvl, const char *name, int type)
383 PJDLOG_ASSERT(nvl->nvl_error == 0);
384 PJDLOG_ASSERT(type == NV_TYPE_NONE ||
385 (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST));
387 nvp = nvlist_find(nvl, type, name);
389 nvlist_free_nvpair(nvl, nvp);
391 nvlist_report_missing(type, name);
395 nvlist_clone(const nvlist_t *nvl)
398 nvpair_t *nvp, *newnvp;
402 if (nvl->nvl_error != 0) {
403 ERRNO_SET(nvl->nvl_error);
407 newnvl = nvlist_create(nvl->nvl_flags & NV_FLAG_PUBLIC_MASK);
408 for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
409 nvp = nvlist_next_nvpair(nvl, nvp)) {
410 newnvp = nvpair_clone(nvp);
413 (void)nvlist_move_nvpair(newnvl, newnvp);
416 nvlist_destroy(newnvl);
424 nvlist_dump_error_check(const nvlist_t *nvl, int fd, int level)
427 if (nvlist_error(nvl) != 0) {
428 dprintf(fd, "%*serror: %d\n", level * 4, "",
437 * Dump content of nvlist.
440 nvlist_dump(const nvlist_t *nvl, int fd)
442 const nvlist_t *tmpnvl;
443 nvpair_t *nvp, *tmpnvp;
448 if (nvlist_dump_error_check(nvl, fd, level))
451 nvp = nvlist_first_nvpair(nvl);
452 while (nvp != NULL) {
453 dprintf(fd, "%*s%s (%s):", level * 4, "", nvpair_name(nvp),
454 nvpair_type_string(nvpair_type(nvp)));
455 switch (nvpair_type(nvp)) {
457 dprintf(fd, " null\n");
460 dprintf(fd, " %s\n", nvpair_get_bool(nvp) ?
464 dprintf(fd, " %ju (%jd) (0x%jx)\n",
465 (uintmax_t)nvpair_get_number(nvp),
466 (intmax_t)nvpair_get_number(nvp),
467 (uintmax_t)nvpair_get_number(nvp));
470 dprintf(fd, " [%s]\n", nvpair_get_string(nvp));
474 tmpnvl = nvpair_get_nvlist(nvp);
475 if (nvlist_dump_error_check(tmpnvl, fd, level + 1))
477 tmpnvp = nvlist_first_nvpair(tmpnvl);
478 if (tmpnvp != NULL) {
485 case NV_TYPE_DESCRIPTOR:
486 dprintf(fd, " %d\n", nvpair_get_descriptor(nvp));
490 const unsigned char *binary;
494 binary = nvpair_get_binary(nvp, &size);
495 dprintf(fd, " %zu ", size);
496 for (ii = 0; ii < size; ii++)
497 dprintf(fd, "%02hhx", binary[ii]);
501 case NV_TYPE_BOOL_ARRAY:
507 value = nvpair_get_bool_array(nvp, &nitems);
509 for (ii = 0; ii < nitems; ii++) {
510 dprintf(fd, "%s", value[ii] ? "TRUE" : "FALSE");
511 if (ii != nitems - 1)
517 case NV_TYPE_STRING_ARRAY:
519 const char * const *value;
523 value = nvpair_get_string_array(nvp, &nitems);
525 for (ii = 0; ii < nitems; ii++) {
526 if (value[ii] == NULL)
529 dprintf(fd, "\"%s\"", value[ii]);
530 if (ii != nitems - 1)
536 case NV_TYPE_NUMBER_ARRAY:
538 const uint64_t *value;
542 value = nvpair_get_number_array(nvp, &nitems);
544 for (ii = 0; ii < nitems; ii++) {
545 dprintf(fd, "%ju (%jd) (0x%jx)",
546 value[ii], value[ii], value[ii]);
547 if (ii != nitems - 1)
553 case NV_TYPE_DESCRIPTOR_ARRAY:
559 value = nvpair_get_descriptor_array(nvp, &nitems);
561 for (ii = 0; ii < nitems; ii++) {
562 dprintf(fd, "%d", value[ii]);
563 if (ii != nitems - 1)
569 case NV_TYPE_NVLIST_ARRAY:
571 const nvlist_t * const *value;
575 value = nvpair_get_nvlist_array(nvp, &nitems);
576 dprintf(fd, " %zu\n", nitems);
579 for (ii = 0; ii < nitems; ii++) {
580 if (nvlist_dump_error_check(value[ii], fd,
585 if (tmpnvl == NULL) {
586 tmpnvp = nvlist_first_nvpair(value[ii]);
587 if (tmpnvp != NULL) {
590 dprintf(fd, "%*s,\n",
591 (level + 1) * 4, "");
595 if (tmpnvp != NULL) {
604 PJDLOG_ABORT("Unknown type: %d.", nvpair_type(nvp));
607 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
610 if (nvlist_in_array(nvl))
611 dprintf(fd, "%*s,\n", level * 4, "");
612 nvl = nvlist_get_pararr(nvl, &cookie);
615 if (nvlist_in_array(nvl) && cookie == NULL) {
616 nvp = nvlist_first_nvpair(nvl);
621 } while (nvp == NULL);
622 if (nvlist_in_array(nvl) && cookie == NULL)
629 nvlist_fdump(const nvlist_t *nvl, FILE *fp)
633 nvlist_dump(nvl, fileno(fp));
638 * The function obtains size of the nvlist after nvlist_pack().
641 nvlist_size(const nvlist_t *nvl)
643 const nvlist_t *tmpnvl;
644 const nvlist_t * const *nvlarray;
645 const nvpair_t *nvp, *tmpnvp;
651 PJDLOG_ASSERT(nvl->nvl_error == 0);
653 size = sizeof(struct nvlist_header);
654 nvp = nvlist_first_nvpair(nvl);
655 while (nvp != NULL) {
656 size += nvpair_header_size();
657 size += strlen(nvpair_name(nvp)) + 1;
658 if (nvpair_type(nvp) == NV_TYPE_NVLIST) {
659 size += sizeof(struct nvlist_header);
660 size += nvpair_header_size() + 1;
661 tmpnvl = nvpair_get_nvlist(nvp);
662 PJDLOG_ASSERT(tmpnvl->nvl_error == 0);
663 tmpnvp = nvlist_first_nvpair(tmpnvl);
664 if (tmpnvp != NULL) {
669 } else if (nvpair_type(nvp) == NV_TYPE_NVLIST_ARRAY) {
670 nvlarray = nvpair_get_nvlist_array(nvp, &nitems);
671 PJDLOG_ASSERT(nitems > 0);
673 size += (nvpair_header_size() + 1) * nitems;
674 size += sizeof(struct nvlist_header) * nitems;
678 for (ii = 0; ii < nitems; ii++) {
679 PJDLOG_ASSERT(nvlarray[ii]->nvl_error == 0);
680 tmpnvp = nvlist_first_nvpair(nvlarray[ii]);
681 if (tmpnvp != NULL) {
682 tmpnvl = nvlarray[ii];
686 if (tmpnvp != NULL) {
693 size += nvpair_size(nvp);
696 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
699 nvl = nvlist_get_pararr(nvl, &cookie);
702 if (nvlist_in_array(nvl) && cookie == NULL) {
703 nvp = nvlist_first_nvpair(nvl);
707 } while (nvp == NULL);
708 if (nvlist_in_array(nvl) && cookie == NULL)
719 nvlist_xdescriptors(const nvlist_t *nvl, int *descs)
726 PJDLOG_ASSERT(nvl->nvl_error == 0);
730 while (nvlist_next(nvl, &type, &cookie) != NULL) {
733 case NV_TYPE_DESCRIPTOR:
734 *descs = nvpair_get_descriptor(nvp);
737 case NV_TYPE_DESCRIPTOR_ARRAY:
743 value = nvpair_get_descriptor_array(nvp,
745 for (ii = 0; ii < nitems; ii++) {
752 nvl = nvpair_get_nvlist(nvp);
755 case NV_TYPE_NVLIST_ARRAY:
757 const nvlist_t * const *value;
760 value = nvpair_get_nvlist_array(nvp, &nitems);
761 PJDLOG_ASSERT(value != NULL);
762 PJDLOG_ASSERT(nitems > 0);
770 } while ((nvl = nvlist_get_pararr(nvl, &cookie)) != NULL);
778 nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp)
783 nitems = nvlist_ndescriptors(nvl);
784 fds = nv_malloc(sizeof(fds[0]) * (nitems + 1));
788 nvlist_xdescriptors(nvl, fds);
797 nvlist_ndescriptors(const nvlist_t *nvl)
806 PJDLOG_ASSERT(nvl->nvl_error == 0);
811 while (nvlist_next(nvl, &type, &cookie) != NULL) {
814 case NV_TYPE_DESCRIPTOR:
818 nvl = nvpair_get_nvlist(nvp);
821 case NV_TYPE_NVLIST_ARRAY:
823 const nvlist_t * const *value;
826 value = nvpair_get_nvlist_array(nvp, &nitems);
827 PJDLOG_ASSERT(value != NULL);
828 PJDLOG_ASSERT(nitems > 0);
834 case NV_TYPE_DESCRIPTOR_ARRAY:
838 (void)nvpair_get_descriptor_array(nvp,
845 } while ((nvl = nvlist_get_pararr(nvl, &cookie)) != NULL);
853 static unsigned char *
854 nvlist_pack_header(const nvlist_t *nvl, unsigned char *ptr, size_t *leftp)
856 struct nvlist_header nvlhdr;
860 nvlhdr.nvlh_magic = NVLIST_HEADER_MAGIC;
861 nvlhdr.nvlh_version = NVLIST_HEADER_VERSION;
862 nvlhdr.nvlh_flags = nvl->nvl_flags;
863 #if BYTE_ORDER == BIG_ENDIAN
864 nvlhdr.nvlh_flags |= NV_FLAG_BIG_ENDIAN;
866 nvlhdr.nvlh_descriptors = nvlist_ndescriptors(nvl);
867 nvlhdr.nvlh_size = *leftp - sizeof(nvlhdr);
868 PJDLOG_ASSERT(*leftp >= sizeof(nvlhdr));
869 memcpy(ptr, &nvlhdr, sizeof(nvlhdr));
870 ptr += sizeof(nvlhdr);
871 *leftp -= sizeof(nvlhdr);
877 nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep)
879 unsigned char *buf, *ptr;
881 const nvlist_t *tmpnvl;
882 nvpair_t *nvp, *tmpnvp;
887 if (nvl->nvl_error != 0) {
888 ERRNO_SET(nvl->nvl_error);
892 size = nvlist_size(nvl);
893 buf = nv_malloc(size);
900 ptr = nvlist_pack_header(nvl, ptr, &left);
902 nvp = nvlist_first_nvpair(nvl);
903 while (nvp != NULL) {
906 nvpair_init_datasize(nvp);
907 ptr = nvpair_pack_header(nvp, ptr, &left);
910 switch (nvpair_type(nvp)) {
912 ptr = nvpair_pack_null(nvp, ptr, &left);
915 ptr = nvpair_pack_bool(nvp, ptr, &left);
918 ptr = nvpair_pack_number(nvp, ptr, &left);
921 ptr = nvpair_pack_string(nvp, ptr, &left);
924 tmpnvl = nvpair_get_nvlist(nvp);
925 ptr = nvlist_pack_header(tmpnvl, ptr, &left);
928 tmpnvp = nvlist_first_nvpair(tmpnvl);
929 if (tmpnvp != NULL) {
934 ptr = nvpair_pack_nvlist_up(ptr, &left);
937 case NV_TYPE_DESCRIPTOR:
938 ptr = nvpair_pack_descriptor(nvp, ptr, fdidxp, &left);
940 case NV_TYPE_DESCRIPTOR_ARRAY:
941 ptr = nvpair_pack_descriptor_array(nvp, ptr, fdidxp,
946 ptr = nvpair_pack_binary(nvp, ptr, &left);
948 case NV_TYPE_BOOL_ARRAY:
949 ptr = nvpair_pack_bool_array(nvp, ptr, &left);
951 case NV_TYPE_NUMBER_ARRAY:
952 ptr = nvpair_pack_number_array(nvp, ptr, &left);
954 case NV_TYPE_STRING_ARRAY:
955 ptr = nvpair_pack_string_array(nvp, ptr, &left);
957 case NV_TYPE_NVLIST_ARRAY:
959 const nvlist_t * const * value;
964 value = nvpair_get_nvlist_array(nvp, &nitems);
965 for (ii = 0; ii < nitems; ii++) {
966 ptr = nvlist_pack_header(value[ii], ptr, &left);
969 tmpnvp = nvlist_first_nvpair(value[ii]);
970 if (tmpnvp != NULL) {
974 ptr = nvpair_pack_nvlist_array_next(ptr, &left);
978 if (tmpnvl != NULL) {
986 PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp));
990 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
993 if (nvlist_in_array(nvl)) {
994 ptr = nvpair_pack_nvlist_array_next(ptr,
999 nvl = nvlist_get_pararr(nvl, &cookie);
1002 if (nvlist_in_array(nvl) && cookie == NULL) {
1003 nvp = nvlist_first_nvpair(nvl);
1004 ptr = nvlist_pack_header(nvl, ptr,
1008 } else if (nvpair_type((nvpair_t *)cookie) !=
1009 NV_TYPE_NVLIST_ARRAY) {
1010 ptr = nvpair_pack_nvlist_up(ptr, &left);
1017 } while (nvp == NULL);
1018 if (nvlist_in_array(nvl) && cookie == NULL)
1033 nvlist_pack(const nvlist_t *nvl, size_t *sizep)
1038 if (nvl->nvl_error != 0) {
1039 ERRNO_SET(nvl->nvl_error);
1043 if (nvlist_ndescriptors(nvl) > 0) {
1044 ERRNO_SET(EOPNOTSUPP);
1048 return (nvlist_xpack(nvl, NULL, sizep));
1052 nvlist_check_header(struct nvlist_header *nvlhdrp)
1055 if (nvlhdrp->nvlh_magic != NVLIST_HEADER_MAGIC) {
1059 if ((nvlhdrp->nvlh_flags & ~NV_FLAG_ALL_MASK) != 0) {
1063 #if BYTE_ORDER == BIG_ENDIAN
1064 if ((nvlhdrp->nvlh_flags & NV_FLAG_BIG_ENDIAN) == 0) {
1065 nvlhdrp->nvlh_size = le64toh(nvlhdrp->nvlh_size);
1066 nvlhdrp->nvlh_descriptors = le64toh(nvlhdrp->nvlh_descriptors);
1069 if ((nvlhdrp->nvlh_flags & NV_FLAG_BIG_ENDIAN) != 0) {
1070 nvlhdrp->nvlh_size = be64toh(nvlhdrp->nvlh_size);
1071 nvlhdrp->nvlh_descriptors = be64toh(nvlhdrp->nvlh_descriptors);
1077 const unsigned char *
1078 nvlist_unpack_header(nvlist_t *nvl, const unsigned char *ptr, size_t nfds,
1079 bool *isbep, size_t *leftp)
1081 struct nvlist_header nvlhdr;
1084 if (*leftp < sizeof(nvlhdr))
1087 memcpy(&nvlhdr, ptr, sizeof(nvlhdr));
1089 if (!nvlist_check_header(&nvlhdr))
1092 if (nvlhdr.nvlh_size != *leftp - sizeof(nvlhdr))
1096 * nvlh_descriptors might be smaller than nfds in embedded nvlists.
1098 if (nvlhdr.nvlh_descriptors > nfds)
1101 if ((nvlhdr.nvlh_flags & ~NV_FLAG_ALL_MASK) != 0)
1104 inarrayf = (nvl->nvl_flags & NV_FLAG_IN_ARRAY);
1105 nvl->nvl_flags = (nvlhdr.nvlh_flags & NV_FLAG_PUBLIC_MASK) | inarrayf;
1107 ptr += sizeof(nvlhdr);
1109 *isbep = (((int)nvlhdr.nvlh_flags & NV_FLAG_BIG_ENDIAN) != 0);
1110 *leftp -= sizeof(nvlhdr);
1119 nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds,
1122 const unsigned char *ptr;
1123 nvlist_t *nvl, *retnvl, *tmpnvl, *array;
1128 PJDLOG_ASSERT((flags & ~(NV_FLAG_PUBLIC_MASK)) == 0);
1133 tmpnvl = array = NULL;
1134 nvl = retnvl = nvlist_create(0);
1138 ptr = nvlist_unpack_header(nvl, ptr, nfds, &isbe, &left);
1141 if (nvl->nvl_flags != flags) {
1147 ptr = nvpair_unpack(isbe, ptr, &left, &nvp);
1150 switch (nvpair_type(nvp)) {
1152 ptr = nvpair_unpack_null(isbe, nvp, ptr, &left);
1155 ptr = nvpair_unpack_bool(isbe, nvp, ptr, &left);
1157 case NV_TYPE_NUMBER:
1158 ptr = nvpair_unpack_number(isbe, nvp, ptr, &left);
1160 case NV_TYPE_STRING:
1161 ptr = nvpair_unpack_string(isbe, nvp, ptr, &left);
1163 case NV_TYPE_NVLIST:
1164 ptr = nvpair_unpack_nvlist(isbe, nvp, ptr, &left, nfds,
1166 if (tmpnvl == NULL || ptr == NULL)
1168 nvlist_set_parent(tmpnvl, nvp);
1171 case NV_TYPE_DESCRIPTOR:
1172 ptr = nvpair_unpack_descriptor(isbe, nvp, ptr, &left,
1175 case NV_TYPE_DESCRIPTOR_ARRAY:
1176 ptr = nvpair_unpack_descriptor_array(isbe, nvp, ptr,
1180 case NV_TYPE_BINARY:
1181 ptr = nvpair_unpack_binary(isbe, nvp, ptr, &left);
1183 case NV_TYPE_NVLIST_UP:
1184 if (nvl->nvl_parent == NULL)
1186 nvl = nvpair_nvlist(nvl->nvl_parent);
1187 nvpair_free_structure(nvp);
1189 case NV_TYPE_NVLIST_ARRAY_NEXT:
1190 if (nvl->nvl_array_next == NULL) {
1191 if (nvl->nvl_parent == NULL)
1193 nvl = nvpair_nvlist(nvl->nvl_parent);
1195 nvl = __DECONST(nvlist_t *,
1196 nvlist_get_array_next(nvl));
1197 ptr = nvlist_unpack_header(nvl, ptr, nfds,
1202 nvpair_free_structure(nvp);
1204 case NV_TYPE_BOOL_ARRAY:
1205 ptr = nvpair_unpack_bool_array(isbe, nvp, ptr, &left);
1207 case NV_TYPE_NUMBER_ARRAY:
1208 ptr = nvpair_unpack_number_array(isbe, nvp, ptr, &left);
1210 case NV_TYPE_STRING_ARRAY:
1211 ptr = nvpair_unpack_string_array(isbe, nvp, ptr, &left);
1213 case NV_TYPE_NVLIST_ARRAY:
1214 ptr = nvpair_unpack_nvlist_array(isbe, nvp, ptr, &left,
1218 PJDLOG_ASSERT(array != NULL);
1221 nvlist_set_parent(array, nvp);
1222 array = __DECONST(nvlist_t *,
1223 nvlist_get_array_next(array));
1224 } while (array != NULL);
1225 ptr = nvlist_unpack_header(tmpnvl, ptr, nfds, &isbe,
1229 PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp));
1233 if (!nvlist_move_nvpair(nvl, nvp))
1235 if (tmpnvl != NULL) {
1243 nvlist_destroy(retnvl);
1248 nvlist_unpack(const void *buf, size_t size, int flags)
1251 return (nvlist_xunpack(buf, size, NULL, 0, flags));
1256 nvlist_send(int sock, const nvlist_t *nvl)
1258 size_t datasize, nfds;
1264 if (nvlist_error(nvl) != 0) {
1265 ERRNO_SET(nvlist_error(nvl));
1269 fds = nvlist_descriptors(nvl, &nfds);
1276 data = nvlist_xpack(nvl, &fdidx, &datasize);
1280 if (buf_send(sock, data, datasize) == -1)
1284 if (fd_send(sock, fds, nfds) == -1)
1298 nvlist_recv(int sock, int flags)
1300 struct nvlist_header nvlhdr;
1301 nvlist_t *nvl, *ret;
1303 size_t nfds, size, i;
1306 if (buf_recv(sock, &nvlhdr, sizeof(nvlhdr)) == -1)
1309 if (!nvlist_check_header(&nvlhdr))
1312 nfds = (size_t)nvlhdr.nvlh_descriptors;
1313 size = sizeof(nvlhdr) + (size_t)nvlhdr.nvlh_size;
1315 buf = nv_malloc(size);
1319 memcpy(buf, &nvlhdr, sizeof(nvlhdr));
1324 if (buf_recv(sock, buf + sizeof(nvlhdr), size - sizeof(nvlhdr)) == -1)
1328 fds = nv_malloc(nfds * sizeof(fds[0]));
1331 if (fd_recv(sock, fds, nfds) == -1)
1335 nvl = nvlist_xunpack(buf, size, fds, nfds, flags);
1338 for (i = 0; i < nfds; i++)
1355 nvlist_xfer(int sock, nvlist_t *nvl, int flags)
1358 if (nvlist_send(sock, nvl) < 0) {
1359 nvlist_destroy(nvl);
1362 nvlist_destroy(nvl);
1363 return (nvlist_recv(sock, flags));
1368 nvlist_first_nvpair(const nvlist_t *nvl)
1373 return (TAILQ_FIRST(&nvl->nvl_head));
1377 nvlist_next_nvpair(const nvlist_t *nvl __unused, const nvpair_t *nvp)
1383 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
1385 retnvp = nvpair_next(nvp);
1386 PJDLOG_ASSERT(retnvp == NULL || nvpair_nvlist(retnvp) == nvl);
1393 nvlist_prev_nvpair(const nvlist_t *nvl __unused, const nvpair_t *nvp)
1399 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
1401 retnvp = nvpair_prev(nvp);
1402 PJDLOG_ASSERT(nvpair_nvlist(retnvp) == nvl);
1408 nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep)
1414 if (cookiep == NULL || *cookiep == NULL)
1415 nvp = nvlist_first_nvpair(nvl);
1417 nvp = nvlist_next_nvpair(nvl, *cookiep);
1421 *typep = nvpair_type(nvp);
1422 if (cookiep != NULL)
1424 return (nvpair_name(nvp));
1428 nvlist_exists(const nvlist_t *nvl, const char *name)
1431 return (nvlist_find(nvl, NV_TYPE_NONE, name) != NULL);
1434 #define NVLIST_EXISTS(type, TYPE) \
1436 nvlist_exists_##type(const nvlist_t *nvl, const char *name) \
1439 return (nvlist_find(nvl, NV_TYPE_##TYPE, name) != NULL); \
1442 NVLIST_EXISTS(null, NULL)
1443 NVLIST_EXISTS(bool, BOOL)
1444 NVLIST_EXISTS(number, NUMBER)
1445 NVLIST_EXISTS(string, STRING)
1446 NVLIST_EXISTS(nvlist, NVLIST)
1447 NVLIST_EXISTS(binary, BINARY)
1448 NVLIST_EXISTS(bool_array, BOOL_ARRAY)
1449 NVLIST_EXISTS(number_array, NUMBER_ARRAY)
1450 NVLIST_EXISTS(string_array, STRING_ARRAY)
1451 NVLIST_EXISTS(nvlist_array, NVLIST_ARRAY)
1453 NVLIST_EXISTS(descriptor, DESCRIPTOR)
1454 NVLIST_EXISTS(descriptor_array, DESCRIPTOR_ARRAY)
1457 #undef NVLIST_EXISTS
1460 nvlist_add_nvpair(nvlist_t *nvl, const nvpair_t *nvp)
1466 if (nvlist_error(nvl) != 0) {
1467 ERRNO_SET(nvlist_error(nvl));
1470 if ((nvl->nvl_flags & NV_FLAG_NO_UNIQUE) == 0) {
1471 if (nvlist_exists(nvl, nvpair_name(nvp))) {
1472 nvl->nvl_error = EEXIST;
1473 ERRNO_SET(nvlist_error(nvl));
1478 newnvp = nvpair_clone(nvp);
1479 if (newnvp == NULL) {
1480 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1481 ERRNO_SET(nvlist_error(nvl));
1485 nvpair_insert(&nvl->nvl_head, newnvp, nvl);
1489 nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...)
1493 va_start(valueap, valuefmt);
1494 nvlist_add_stringv(nvl, name, valuefmt, valueap);
1499 nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt,
1504 if (nvlist_error(nvl) != 0) {
1505 ERRNO_SET(nvlist_error(nvl));
1509 nvp = nvpair_create_stringv(name, valuefmt, valueap);
1511 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1512 ERRNO_SET(nvl->nvl_error);
1514 (void)nvlist_move_nvpair(nvl, nvp);
1519 nvlist_add_null(nvlist_t *nvl, const char *name)
1523 if (nvlist_error(nvl) != 0) {
1524 ERRNO_SET(nvlist_error(nvl));
1528 nvp = nvpair_create_null(name);
1530 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1531 ERRNO_SET(nvl->nvl_error);
1533 (void)nvlist_move_nvpair(nvl, nvp);
1538 nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value,
1543 if (nvlist_error(nvl) != 0) {
1544 ERRNO_SET(nvlist_error(nvl));
1548 nvp = nvpair_create_binary(name, value, size);
1550 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1551 ERRNO_SET(nvl->nvl_error);
1553 (void)nvlist_move_nvpair(nvl, nvp);
1558 #define NVLIST_ADD(vtype, type) \
1560 nvlist_add_##type(nvlist_t *nvl, const char *name, vtype value) \
1564 if (nvlist_error(nvl) != 0) { \
1565 ERRNO_SET(nvlist_error(nvl)); \
1569 nvp = nvpair_create_##type(name, value); \
1570 if (nvp == NULL) { \
1571 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); \
1572 ERRNO_SET(nvl->nvl_error); \
1574 (void)nvlist_move_nvpair(nvl, nvp); \
1578 NVLIST_ADD(bool, bool)
1579 NVLIST_ADD(uint64_t, number)
1580 NVLIST_ADD(const char *, string)
1581 NVLIST_ADD(const nvlist_t *, nvlist)
1583 NVLIST_ADD(int, descriptor);
1588 #define NVLIST_ADD_ARRAY(vtype, type) \
1590 nvlist_add_##type##_array(nvlist_t *nvl, const char *name, vtype value, \
1595 if (nvlist_error(nvl) != 0) { \
1596 ERRNO_SET(nvlist_error(nvl)); \
1600 nvp = nvpair_create_##type##_array(name, value, nitems); \
1601 if (nvp == NULL) { \
1602 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); \
1603 ERRNO_SET(nvl->nvl_error); \
1605 (void)nvlist_move_nvpair(nvl, nvp); \
1609 NVLIST_ADD_ARRAY(const bool *, bool)
1610 NVLIST_ADD_ARRAY(const uint64_t *, number)
1611 NVLIST_ADD_ARRAY(const char * const *, string)
1612 NVLIST_ADD_ARRAY(const nvlist_t * const *, nvlist)
1614 NVLIST_ADD_ARRAY(const int *, descriptor)
1617 #undef NVLIST_ADD_ARRAY
1619 #define NVLIST_APPEND_ARRAY(vtype, type, TYPE) \
1621 nvlist_append_##type##_array(nvlist_t *nvl, const char *name, vtype value)\
1625 if (nvlist_error(nvl) != 0) { \
1626 ERRNO_SET(nvlist_error(nvl)); \
1629 nvp = nvlist_find(nvl, NV_TYPE_##TYPE##_ARRAY, name); \
1630 if (nvp == NULL) { \
1631 nvlist_add_##type##_array(nvl, name, &value, 1); \
1634 if (nvpair_append_##type##_array(nvp, value) == -1) { \
1635 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); \
1636 ERRNO_SET(nvl->nvl_error); \
1640 NVLIST_APPEND_ARRAY(const bool, bool, BOOL)
1641 NVLIST_APPEND_ARRAY(const uint64_t, number, NUMBER)
1642 NVLIST_APPEND_ARRAY(const char *, string, STRING)
1643 NVLIST_APPEND_ARRAY(const nvlist_t *, nvlist, NVLIST)
1645 NVLIST_APPEND_ARRAY(const int, descriptor, DESCRIPTOR)
1648 #undef NVLIST_APPEND_ARRAY
1651 nvlist_move_nvpair(nvlist_t *nvl, nvpair_t *nvp)
1655 PJDLOG_ASSERT(nvpair_nvlist(nvp) == NULL);
1657 if (nvlist_error(nvl) != 0) {
1659 ERRNO_SET(nvlist_error(nvl));
1662 if ((nvl->nvl_flags & NV_FLAG_NO_UNIQUE) == 0) {
1663 if (nvlist_exists(nvl, nvpair_name(nvp))) {
1665 nvl->nvl_error = EEXIST;
1666 ERRNO_SET(nvl->nvl_error);
1671 nvpair_insert(&nvl->nvl_head, nvp, nvl);
1676 nvlist_move_string(nvlist_t *nvl, const char *name, char *value)
1680 if (nvlist_error(nvl) != 0) {
1682 ERRNO_SET(nvlist_error(nvl));
1686 nvp = nvpair_move_string(name, value);
1688 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1689 ERRNO_SET(nvl->nvl_error);
1691 (void)nvlist_move_nvpair(nvl, nvp);
1696 nvlist_move_nvlist(nvlist_t *nvl, const char *name, nvlist_t *value)
1700 if (nvlist_error(nvl) != 0) {
1701 if (value != NULL && nvlist_get_nvpair_parent(value) != NULL)
1702 nvlist_destroy(value);
1703 ERRNO_SET(nvlist_error(nvl));
1707 nvp = nvpair_move_nvlist(name, value);
1709 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1710 ERRNO_SET(nvl->nvl_error);
1712 (void)nvlist_move_nvpair(nvl, nvp);
1718 nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value)
1722 if (nvlist_error(nvl) != 0) {
1724 ERRNO_SET(nvlist_error(nvl));
1728 nvp = nvpair_move_descriptor(name, value);
1730 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1731 ERRNO_SET(nvl->nvl_error);
1733 (void)nvlist_move_nvpair(nvl, nvp);
1739 nvlist_move_binary(nvlist_t *nvl, const char *name, void *value, size_t size)
1743 if (nvlist_error(nvl) != 0) {
1745 ERRNO_SET(nvlist_error(nvl));
1749 nvp = nvpair_move_binary(name, value, size);
1751 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1752 ERRNO_SET(nvl->nvl_error);
1754 (void)nvlist_move_nvpair(nvl, nvp);
1759 nvlist_move_bool_array(nvlist_t *nvl, const char *name, bool *value,
1764 if (nvlist_error(nvl) != 0) {
1766 ERRNO_SET(nvlist_error(nvl));
1770 nvp = nvpair_move_bool_array(name, value, nitems);
1772 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1773 ERRNO_SET(nvl->nvl_error);
1775 (void)nvlist_move_nvpair(nvl, nvp);
1780 nvlist_move_string_array(nvlist_t *nvl, const char *name, char **value,
1786 if (nvlist_error(nvl) != 0) {
1787 if (value != NULL) {
1788 for (i = 0; i < nitems; i++)
1792 ERRNO_SET(nvlist_error(nvl));
1796 nvp = nvpair_move_string_array(name, value, nitems);
1798 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1799 ERRNO_SET(nvl->nvl_error);
1801 (void)nvlist_move_nvpair(nvl, nvp);
1806 nvlist_move_nvlist_array(nvlist_t *nvl, const char *name, nvlist_t **value,
1812 if (nvlist_error(nvl) != 0) {
1813 if (value != NULL) {
1814 for (i = 0; i < nitems; i++) {
1815 if (nvlist_get_pararr(value[i], NULL) == NULL)
1816 nvlist_destroy(value[i]);
1820 ERRNO_SET(nvlist_error(nvl));
1824 nvp = nvpair_move_nvlist_array(name, value, nitems);
1826 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1827 ERRNO_SET(nvl->nvl_error);
1829 (void)nvlist_move_nvpair(nvl, nvp);
1834 nvlist_move_number_array(nvlist_t *nvl, const char *name, uint64_t *value,
1839 if (nvlist_error(nvl) != 0) {
1841 ERRNO_SET(nvlist_error(nvl));
1845 nvp = nvpair_move_number_array(name, value, nitems);
1847 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1848 ERRNO_SET(nvl->nvl_error);
1850 (void)nvlist_move_nvpair(nvl, nvp);
1856 nvlist_move_descriptor_array(nvlist_t *nvl, const char *name, int *value,
1862 if (nvlist_error(nvl) != 0) {
1864 for (i = 0; i < nitems; i++)
1869 ERRNO_SET(nvlist_error(nvl));
1873 nvp = nvpair_move_descriptor_array(name, value, nitems);
1875 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1876 ERRNO_SET(nvl->nvl_error);
1878 (void)nvlist_move_nvpair(nvl, nvp);
1884 nvlist_get_nvpair(const nvlist_t *nvl, const char *name)
1887 return (nvlist_find(nvl, NV_TYPE_NONE, name));
1890 #define NVLIST_GET(ftype, type, TYPE) \
1892 nvlist_get_##type(const nvlist_t *nvl, const char *name) \
1894 const nvpair_t *nvp; \
1896 nvp = nvlist_find(nvl, NV_TYPE_##TYPE, name); \
1898 nvlist_report_missing(NV_TYPE_##TYPE, name); \
1899 return (nvpair_get_##type(nvp)); \
1902 NVLIST_GET(bool, bool, BOOL)
1903 NVLIST_GET(uint64_t, number, NUMBER)
1904 NVLIST_GET(const char *, string, STRING)
1905 NVLIST_GET(const nvlist_t *, nvlist, NVLIST)
1907 NVLIST_GET(int, descriptor, DESCRIPTOR)
1913 nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep)
1917 nvp = nvlist_find(nvl, NV_TYPE_BINARY, name);
1919 nvlist_report_missing(NV_TYPE_BINARY, name);
1921 return (nvpair_get_binary(nvp, sizep));
1924 #define NVLIST_GET_ARRAY(ftype, type, TYPE) \
1926 nvlist_get_##type##_array(const nvlist_t *nvl, const char *name, \
1929 const nvpair_t *nvp; \
1931 nvp = nvlist_find(nvl, NV_TYPE_##TYPE##_ARRAY, name); \
1933 nvlist_report_missing(NV_TYPE_##TYPE##_ARRAY, name); \
1934 return (nvpair_get_##type##_array(nvp, nitems)); \
1937 NVLIST_GET_ARRAY(const bool *, bool, BOOL)
1938 NVLIST_GET_ARRAY(const uint64_t *, number, NUMBER)
1939 NVLIST_GET_ARRAY(const char * const *, string, STRING)
1940 NVLIST_GET_ARRAY(const nvlist_t * const *, nvlist, NVLIST)
1942 NVLIST_GET_ARRAY(const int *, descriptor, DESCRIPTOR)
1945 #undef NVLIST_GET_ARRAY
1947 #define NVLIST_TAKE(ftype, type, TYPE) \
1949 nvlist_take_##type(nvlist_t *nvl, const char *name) \
1954 nvp = nvlist_find(nvl, NV_TYPE_##TYPE, name); \
1956 nvlist_report_missing(NV_TYPE_##TYPE, name); \
1957 value = (ftype)(intptr_t)nvpair_get_##type(nvp); \
1958 nvlist_remove_nvpair(nvl, nvp); \
1959 nvpair_free_structure(nvp); \
1963 NVLIST_TAKE(bool, bool, BOOL)
1964 NVLIST_TAKE(uint64_t, number, NUMBER)
1965 NVLIST_TAKE(char *, string, STRING)
1966 NVLIST_TAKE(nvlist_t *, nvlist, NVLIST)
1968 NVLIST_TAKE(int, descriptor, DESCRIPTOR)
1974 nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep)
1979 nvp = nvlist_find(nvl, NV_TYPE_BINARY, name);
1981 nvlist_report_missing(NV_TYPE_BINARY, name);
1983 value = (void *)(intptr_t)nvpair_get_binary(nvp, sizep);
1984 nvlist_remove_nvpair(nvl, nvp);
1985 nvpair_free_structure(nvp);
1989 #define NVLIST_TAKE_ARRAY(ftype, type, TYPE) \
1991 nvlist_take_##type##_array(nvlist_t *nvl, const char *name, \
1997 nvp = nvlist_find(nvl, NV_TYPE_##TYPE##_ARRAY, name); \
1999 nvlist_report_missing(NV_TYPE_##TYPE##_ARRAY, name); \
2000 value = (ftype)(intptr_t)nvpair_get_##type##_array(nvp, nitems);\
2001 nvlist_remove_nvpair(nvl, nvp); \
2002 nvpair_free_structure(nvp); \
2006 NVLIST_TAKE_ARRAY(bool *, bool, BOOL)
2007 NVLIST_TAKE_ARRAY(uint64_t *, number, NUMBER)
2008 NVLIST_TAKE_ARRAY(char **, string, STRING)
2009 NVLIST_TAKE_ARRAY(nvlist_t **, nvlist, NVLIST)
2011 NVLIST_TAKE_ARRAY(int *, descriptor, DESCRIPTOR)
2015 nvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp)
2020 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
2022 nvpair_remove(&nvl->nvl_head, nvp, nvl);
2026 nvlist_free(nvlist_t *nvl, const char *name)
2029 nvlist_free_type(nvl, name, NV_TYPE_NONE);
2032 #define NVLIST_FREE(type, TYPE) \
2034 nvlist_free_##type(nvlist_t *nvl, const char *name) \
2037 nvlist_free_type(nvl, name, NV_TYPE_##TYPE); \
2040 NVLIST_FREE(null, NULL)
2041 NVLIST_FREE(bool, BOOL)
2042 NVLIST_FREE(number, NUMBER)
2043 NVLIST_FREE(string, STRING)
2044 NVLIST_FREE(nvlist, NVLIST)
2045 NVLIST_FREE(binary, BINARY)
2046 NVLIST_FREE(bool_array, BOOL_ARRAY)
2047 NVLIST_FREE(number_array, NUMBER_ARRAY)
2048 NVLIST_FREE(string_array, STRING_ARRAY)
2049 NVLIST_FREE(nvlist_array, NVLIST_ARRAY)
2051 NVLIST_FREE(descriptor, DESCRIPTOR)
2052 NVLIST_FREE(descriptor_array, DESCRIPTOR_ARRAY)
2058 nvlist_free_nvpair(nvlist_t *nvl, nvpair_t *nvp)
2063 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
2065 nvlist_remove_nvpair(nvl, nvp);