Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net - Improve the comments in bpf.h and KNF a little.
details: https://anonhg.NetBSD.org/src/rev/50f73cb6f488
branches: trunk
changeset: 330146:50f73cb6f488
user: rmind <rmind%NetBSD.org@localhost>
date: Tue Jun 24 22:19:36 2014 +0000
description:
- Improve the comments in bpf.h and KNF a little.
- Rename bpf_ctx_t member noinit to preinited (reflects the meaning better).
diffstat:
sys/net/bpf.h | 62 ++++++++++++++++++++++++++-------------------------
sys/net/bpf_filter.c | 15 ++++++-----
sys/net/bpfjit.c | 16 ++++++------
3 files changed, 48 insertions(+), 45 deletions(-)
diffs (225 lines):
diff -r 1e0b841e8d2d -r 50f73cb6f488 sys/net/bpf.h
--- a/sys/net/bpf.h Tue Jun 24 16:39:39 2014 +0000
+++ b/sys/net/bpf.h Tue Jun 24 22:19:36 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bpf.h,v 1.64 2014/06/24 10:53:30 alnsn Exp $ */
+/* $NetBSD: bpf.h,v 1.65 2014/06/24 22:19:36 rmind Exp $ */
/*
* Copyright (c) 1990, 1991, 1993
@@ -280,19 +280,16 @@
/*
* Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
*/
-#define BPF_MEMWORDS 16
+#define BPF_MEMWORDS 16
/*
- * Each bit in bpf_memword_init_t value indicates if the corresponding
- * external memory word is initialised prior to calling a bpf program.
- * Note that when used internally, a meaning is often flipped: bits
- * indicate which memory words need to be initialised prior to
- * executing a bpf program.
+ * bpf_memword_init_t: bits indicate which words in the external memory
+ * store will be initialised by the caller before BPF program execution.
*/
typedef uint32_t bpf_memword_init_t;
-#define BPF_MEMWORD_INIT(k) (UINT32_C(1) << (k))
+#define BPF_MEMWORD_INIT(k) (UINT32_C(1) << (k))
-/* Two most significant bits are reserved by bpfjit. */
+/* Note: two most significant bits are reserved by bpfjit. */
__CTASSERT(BPF_MEMWORDS + 2 <= sizeof(bpf_memword_init_t) * NBBY);
#ifdef _KERNEL
@@ -300,13 +297,10 @@
* Max number of external memory words (for BPF_LD|BPF_MEM and BPF_ST).
*/
#define BPF_MAX_MEMWORDS 30
+
__CTASSERT(BPF_MAX_MEMWORDS >= BPF_MEMWORDS);
-
-#ifdef __BPF_PRIVATE
-/* Two most significant bits are reserved by bpfjit. */
__CTASSERT(BPF_MAX_MEMWORDS + 2 <= sizeof(bpf_memword_init_t) * NBBY);
#endif
-#endif
/*
* Structure to retrieve available DLTs for the interface.
@@ -319,10 +313,7 @@
struct bpf_ctx;
typedef struct bpf_ctx bpf_ctx_t;
-struct bpf_args;
-typedef struct bpf_args bpf_args_t;
-
-struct bpf_args {
+typedef struct bpf_args {
const uint8_t * pkt;
size_t wirelen;
size_t buflen;
@@ -336,21 +327,32 @@
*/
uint32_t * mem; /* pointer to external memory store */
void * arg; /* auxiliary argument for a copfunc */
-};
+} bpf_args_t;
#if defined(_KERNEL) || defined(__BPF_PRIVATE)
+
typedef uint32_t (*bpf_copfunc_t)(const bpf_ctx_t *, bpf_args_t *, uint32_t);
struct bpf_ctx {
+ /*
+ * BPF coprocessor functions and the number of them.
+ */
const bpf_copfunc_t * copfuncs;
size_t nfuncs;
+
/*
- * Number of external memwords, up to BPF_MAX_MEMWORDS or 0.
- * The latter forces a switch to internal memstore with a
- * fixed number (BPF_MEMWORDS) of memwords.
+ * The number of memory words in the external memory store.
+ * There may be up to BPF_MAX_MEMWORDS words; if zero is set,
+ * then the internal memory store is used which has a fixed
+ * number of words (BPF_MEMWORDS).
*/
size_t extwords;
- bpf_memword_init_t noinit; /* pre-initialised external memwords */
+
+ /*
+ * The bitmask indicating which words in the external memstore
+ * will be initialised by the caller.
+ */
+ bpf_memword_init_t preinited;
};
#endif
@@ -447,20 +449,20 @@
}
-void bpf_setops(void);
+void bpf_setops(void);
-void bpf_ops_handover_enter(struct bpf_ops *);
-void bpf_ops_handover_exit(void);
+void bpf_ops_handover_enter(struct bpf_ops *);
+void bpf_ops_handover_exit(void);
-void bpfilterattach(int);
+void bpfilterattach(int);
bpf_ctx_t *bpf_create(void);
void bpf_destroy(bpf_ctx_t *);
-int bpf_set_cop(bpf_ctx_t *, const bpf_copfunc_t *, size_t);
-int bpf_set_extmem(bpf_ctx_t *, size_t, bpf_memword_init_t);
-u_int bpf_filter_ext(const bpf_ctx_t *, const struct bpf_insn *, bpf_args_t *);
-int bpf_validate_ext(const bpf_ctx_t *, const struct bpf_insn *, int);
+int bpf_set_cop(bpf_ctx_t *, const bpf_copfunc_t *, size_t);
+int bpf_set_extmem(bpf_ctx_t *, size_t, bpf_memword_init_t);
+u_int bpf_filter_ext(const bpf_ctx_t *, const struct bpf_insn *, bpf_args_t *);
+int bpf_validate_ext(const bpf_ctx_t *, const struct bpf_insn *, int);
bpfjit_func_t bpf_jit_generate(bpf_ctx_t *, void *, size_t);
void bpf_jit_freecode(bpfjit_func_t);
diff -r 1e0b841e8d2d -r 50f73cb6f488 sys/net/bpf_filter.c
--- a/sys/net/bpf_filter.c Tue Jun 24 16:39:39 2014 +0000
+++ b/sys/net/bpf_filter.c Tue Jun 24 22:19:36 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bpf_filter.c,v 1.62 2014/06/24 10:53:30 alnsn Exp $ */
+/* $NetBSD: bpf_filter.c,v 1.63 2014/06/24 22:19:36 rmind Exp $ */
/*-
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bpf_filter.c,v 1.62 2014/06/24 10:53:30 alnsn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf_filter.c,v 1.63 2014/06/24 22:19:36 rmind Exp $");
#if 0
#if !(defined(lint) || defined(KERNEL))
@@ -82,7 +82,7 @@
/* XXX check arguments */
bc->extwords = nwords;
- bc->noinit = preinited;
+ bc->preinited = preinited;
return 0;
}
@@ -591,9 +591,9 @@
#if defined(KERNEL) || defined(_KERNEL)
bpf_memword_init_t *mem, invalid;
size_t size;
- const size_t extwords = (bc != NULL) ? bc->extwords : 0;
- const size_t memwords = (extwords != 0) ? extwords : BPF_MEMWORDS;
- const bpf_memword_init_t noinit = (extwords != 0) ? bc->noinit : 0;
+ const size_t extwords = bc ? bc->extwords : 0;
+ const size_t memwords = extwords ? extwords : BPF_MEMWORDS;
+ const bpf_memword_init_t preinited = extwords ? bc->preinited : 0;
#else
const size_t memwords = BPF_MEMWORDS;
#endif
@@ -609,8 +609,9 @@
return 0;
#if defined(KERNEL) || defined(_KERNEL)
+ /* Note: only the pre-initialised is valid on startup */
mem = kmem_zalloc(size = sizeof(*mem) * len, KM_SLEEP);
- invalid = ~noinit; /* Only pre-initialised memory is valid on startup */
+ invalid = ~preinited;
#endif
for (i = 0; i < len; ++i) {
diff -r 1e0b841e8d2d -r 50f73cb6f488 sys/net/bpfjit.c
--- a/sys/net/bpfjit.c Tue Jun 24 16:39:39 2014 +0000
+++ b/sys/net/bpfjit.c Tue Jun 24 22:19:36 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bpfjit.c,v 1.13 2014/06/24 10:53:30 alnsn Exp $ */
+/* $NetBSD: bpfjit.c,v 1.14 2014/06/24 22:19:36 rmind Exp $ */
/*-
* Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
#include <sys/cdefs.h>
#ifdef _KERNEL
-__KERNEL_RCSID(0, "$NetBSD: bpfjit.c,v 1.13 2014/06/24 10:53:30 alnsn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpfjit.c,v 1.14 2014/06/24 22:19:36 rmind Exp $");
#else
-__RCSID("$NetBSD: bpfjit.c,v 1.13 2014/06/24 10:53:30 alnsn Exp $");
+__RCSID("$NetBSD: bpfjit.c,v 1.14 2014/06/24 22:19:36 rmind Exp $");
#endif
#include <sys/types.h>
@@ -1611,9 +1611,9 @@
uint32_t jt, jf;
- const size_t extwords = (bc != NULL) ? bc->extwords : 0;
- const size_t memwords = (extwords != 0) ? extwords : BPF_MEMWORDS;
- const bpf_memword_init_t noinit = (extwords != 0) ? bc->noinit : 0;
+ const size_t extwords = bc ? bc->extwords : 0;
+ const size_t memwords = extwords ? extwords : BPF_MEMWORDS;
+ const bpf_memword_init_t preinited = extwords ? bc->preinited : 0;
rv = NULL;
ret0 = NULL;
@@ -1690,9 +1690,9 @@
/*
* Exclude pre-initialised external memory words but keep
* initialization statuses of A and X registers in case
- * bc->noinit wrongly sets those two bits.
+ * bc->preinited wrongly sets those two bits.
*/
- initmask &= ~noinit | BJ_INIT_ABIT | BJ_INIT_XBIT;
+ initmask &= ~preinited | BJ_INIT_ABIT | BJ_INIT_XBIT;
#if defined(_KERNEL)
/* bpf_filter() checks initialization of memwords. */
Home |
Main Index |
Thread Index |
Old Index