Module Name:    src
Committed By:   christos
Date:           Tue Jun  7 16:27:24 UTC 2022

Modified Files:
        src/lib/libnpf: npf.c

Log Message:
Add method to initialize errinfo so that npfctl does not print random strings.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/lib/libnpf/npf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libnpf/npf.c
diff -u src/lib/libnpf/npf.c:1.49 src/lib/libnpf/npf.c:1.50
--- src/lib/libnpf/npf.c:1.49	Sat May 30 10:16:56 2020
+++ src/lib/libnpf/npf.c	Tue Jun  7 12:27:24 2022
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.49 2020/05/30 14:16:56 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.50 2022/06/07 16:27:24 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/mman.h>
@@ -206,6 +206,20 @@ _npf_rules_process(nl_config_t *ncf, nvl
 }
 
 /*
+ * _npf_init_error: initialize the error structure with the message
+ * from the current error number
+ */
+static int
+_npf_init_error(int error, npf_error_t *errinfo)
+{
+	if (error && errinfo) {
+		memset(errinfo, 0, sizeof(*errinfo));
+		errinfo->error_msg = strerror(error);
+	}
+	return error;
+}
+
+/*
  * _npf_extract_error: check the error number field and extract the
  * error details into the npf_error_t structure.
  */
@@ -346,7 +360,7 @@ npf_config_submit(nl_config_t *ncf, int 
 
 	error = _npf_xfer_fd(fd, IOC_NPF_LOAD, ncf->ncf_dict, &resp);
 	if (error) {
-		return error;
+		return _npf_init_error(errno, errinfo);
 	}
 	error = _npf_extract_error(resp, errinfo);
 	nvlist_destroy(resp);
@@ -1258,12 +1272,12 @@ npf_table_replace(int fd, nl_table_t *tl
 
 	/* Ensure const tables are built. */
 	if ((error = _npf_table_build_const(tl)) != 0) {
-		return error;
+		return _npf_init_error(errno, errinfo);
 	}
 	error = _npf_xfer_fd(fd, IOC_NPF_TABLE_REPLACE, tl->table_dict, &resp);
 	if (error) {
 		assert(resp == NULL);
-		return errno;
+		return _npf_init_error(errno, errinfo);
 	}
 	error = _npf_extract_error(resp, errinfo);
 	nvlist_destroy(resp);

Reply via email to