Module Name:    src
Committed By:   rmind
Date:           Mon Jun  8 01:00:43 UTC 2015

Modified Files:
        src/sys/net/npf: npf_ctl.c
        src/usr.sbin/npf/npfctl: npf_bpf_comp.c npf_build.c

Log Message:
- npfctl: fix the confusion in the parser (0/0 case with no other filter).
- Always populate the error dictionary, not only for DEBUG/DIAGNOSTIC.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/net/npf/npf_ctl.c
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/npf/npfctl/npf_bpf_comp.c
cvs rdiff -u -r1.39 -r1.40 src/usr.sbin/npf/npfctl/npf_build.c

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

Modified files:

Index: src/sys/net/npf/npf_ctl.c
diff -u src/sys/net/npf/npf_ctl.c:1.41 src/sys/net/npf/npf_ctl.c:1.42
--- src/sys/net/npf/npf_ctl.c:1.41	Fri Mar 20 23:36:28 2015
+++ src/sys/net/npf/npf_ctl.c	Mon Jun  8 01:00:43 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_ctl.c,v 1.41 2015/03/20 23:36:28 rmind Exp $	*/
+/*	$NetBSD: npf_ctl.c,v 1.42 2015/06/08 01:00:43 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2009-2014 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 1.41 2015/03/20 23:36:28 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 1.42 2015/06/08 01:00:43 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -49,13 +49,9 @@ __KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 
 #include "npf_impl.h"
 #include "npf_conn.h"
 
-#if defined(DEBUG) || defined(DIAGNOSTIC)
 #define	NPF_ERR_DEBUG(e) \
 	prop_dictionary_set_cstring_nocopy((e), "source-file", __FILE__); \
 	prop_dictionary_set_uint32((e), "source-line", __LINE__);
-#else
-#define	NPF_ERR_DEBUG(e)
-#endif
 
 /*
  * npfctl_switch: enable or disable packet inspection.

Index: src/usr.sbin/npf/npfctl/npf_bpf_comp.c
diff -u src/usr.sbin/npf/npfctl/npf_bpf_comp.c:1.7 src/usr.sbin/npf/npfctl/npf_bpf_comp.c:1.8
--- src/usr.sbin/npf/npfctl/npf_bpf_comp.c:1.7	Sun Jun 29 00:05:24 2014
+++ src/usr.sbin/npf/npfctl/npf_bpf_comp.c	Mon Jun  8 01:00:43 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_bpf_comp.c,v 1.7 2014/06/29 00:05:24 rmind Exp $	*/
+/*	$NetBSD: npf_bpf_comp.c,v 1.8 2015/06/08 01:00:43 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2010-2014 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: npf_bpf_comp.c,v 1.7 2014/06/29 00:05:24 rmind Exp $");
+__RCSID("$NetBSD: npf_bpf_comp.c,v 1.8 2015/06/08 01:00:43 rmind Exp $");
 
 #include <stdlib.h>
 #include <stdbool.h>
@@ -189,6 +189,10 @@ npfctl_bpf_complete(npf_bpf_t *ctx)
 	struct bpf_program *bp = &ctx->prog;
 	const u_int retoff = bp->bf_len;
 
+	/* No instructions (optimised out). */
+	if (!bp->bf_len)
+		return NULL;
+
 	/* Add the return fragment (success and failure paths). */
 	struct bpf_insn insns_ret[] = {
 		BPF_STMT(BPF_RET+BPF_K, NPF_BPF_SUCCESS),

Index: src/usr.sbin/npf/npfctl/npf_build.c
diff -u src/usr.sbin/npf/npfctl/npf_build.c:1.39 src/usr.sbin/npf/npfctl/npf_build.c:1.40
--- src/usr.sbin/npf/npfctl/npf_build.c:1.39	Sat Mar 21 00:49:07 2015
+++ src/usr.sbin/npf/npfctl/npf_build.c	Mon Jun  8 01:00:43 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_build.c,v 1.39 2015/03/21 00:49:07 rmind Exp $	*/
+/*	$NetBSD: npf_build.c,v 1.40 2015/06/08 01:00:43 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: npf_build.c,v 1.39 2015/03/21 00:49:07 rmind Exp $");
+__RCSID("$NetBSD: npf_build.c,v 1.40 2015/06/08 01:00:43 rmind Exp $");
 
 #include <sys/types.h>
 #include <sys/mman.h>
@@ -368,6 +368,10 @@ npfctl_build_code(nl_rule_t *rl, sa_fami
 
 	/* Complete BPF byte-code and pass to the rule. */
 	struct bpf_program *bf = npfctl_bpf_complete(bc);
+	if (bf == NULL) {
+		npfctl_bpf_destroy(bc);
+		return true;
+	}
 	len = bf->bf_len * sizeof(struct bpf_insn);
 
 	if (npf_rule_setcode(rl, NPF_CODE_BPF, bf->bf_insns, len) == -1) {

Reply via email to