Subject: Review: BPF enhancements
To: None <tech-net@netbsd.org>
From: Darren Reed <darrenr@reed.wattle.id.au>
List: tech-net
Date: 06/18/2000 17:02:09
Can someone else please look over these patches ? They appear to do the
right thing (including work). My only real concern are alignment issues
with mbufs and some platforms, although BPF_ALIGN (see bpf_filter.c itself)
appears to take care of this(?).
Darren
p.s. I'm also cc'ing the tcpdump-workers list since this is a pretty
fundamental change to boost performance.
*** /sys/net/bpf_filter.c.orig Sun Dec 3 06:37:27 1995
--- /sys/net/bpf_filter.c Sun Jun 18 16:40:25 2000
***************
*** 69,84 ****
#ifdef KERNEL
#include <sys/mbuf.h>
! #define MINDEX(m, k) \
{ \
! register int len = m->m_len; \
\
! while (k >= len) { \
! k -= len; \
! m = m->m_next; \
! if (m == 0) \
return 0; \
! len = m->m_len; \
} \
}
--- 69,84 ----
#ifdef KERNEL
#include <sys/mbuf.h>
! #define MINDEX(_m, _k) \
{ \
! register int _len = (_m)->m_len; \
\
! while (_k >= _len) { \
! _k -= _len; \
! _m = (_m)->m_next; \
! if (_m == 0) \
return 0; \
! _len = (_m)->m_len; \
} \
}
***************
*** 179,184 ****
--- 179,193 ----
register u_long A = 0, X = 0;
register int k;
long mem[BPF_MEMWORDS];
+ #ifdef KERNEL
+ struct mbuf *m = (struct mbuf *)p, *n;
+ int merr;
+
+ if (buflen == 0) {
+ p = mtod(m, char *);
+ buflen = m->m_len;
+ }
+ #endif
if (pc == 0)
/*
***************
*** 207,217 ****
k = pc->k;
if (k + sizeof(long) > buflen) {
#ifdef KERNEL
! int merr;
!
! if (buflen != 0)
! return 0;
! A = m_xword((struct mbuf *)p, k, &merr);
if (merr != 0)
return 0;
continue;
--- 216,222 ----
k = pc->k;
if (k + sizeof(long) > buflen) {
#ifdef KERNEL
! A = m_xword(m, k, &merr);
if (merr != 0)
return 0;
continue;
***************
*** 231,241 ****
k = pc->k;
if (k + sizeof(short) > buflen) {
#ifdef KERNEL
! int merr;
!
! if (buflen != 0)
return 0;
- A = m_xhalf((struct mbuf *)p, k, &merr);
continue;
#else
return 0;
--- 236,244 ----
k = pc->k;
if (k + sizeof(short) > buflen) {
#ifdef KERNEL
! A = m_xhalf(m, k, &merr);
! if (merr != 0)
return 0;
continue;
#else
return 0;
***************
*** 248,260 ****
k = pc->k;
if (k >= buflen) {
#ifdef KERNEL
! register struct mbuf *m;
!
! if (buflen != 0)
! return 0;
! m = (struct mbuf *)p;
! MINDEX(m, k);
! A = mtod(m, u_char *)[k];
continue;
#else
return 0;
--- 251,259 ----
k = pc->k;
if (k >= buflen) {
#ifdef KERNEL
! n = m;
! MINDEX(n, k);
! A = mtod(n, u_char *)[k];
continue;
#else
return 0;
***************
*** 275,285 ****
k = X + pc->k;
if (k + sizeof(long) > buflen) {
#ifdef KERNEL
! int merr;
!
! if (buflen != 0)
! return 0;
! A = m_xword((struct mbuf *)p, k, &merr);
if (merr != 0)
return 0;
continue;
--- 274,280 ----
k = X + pc->k;
if (k + sizeof(long) > buflen) {
#ifdef KERNEL
! A = m_xword(m, k, &merr);
if (merr != 0)
return 0;
continue;
***************
*** 299,309 ****
k = X + pc->k;
if (k + sizeof(short) > buflen) {
#ifdef KERNEL
! int merr;
!
! if (buflen != 0)
! return 0;
! A = m_xhalf((struct mbuf *)p, k, &merr);
if (merr != 0)
return 0;
continue;
--- 294,300 ----
k = X + pc->k;
if (k + sizeof(short) > buflen) {
#ifdef KERNEL
! A = m_xhalf(m, k, &merr);
if (merr != 0)
return 0;
continue;
***************
*** 318,330 ****
k = X + pc->k;
if (k >= buflen) {
#ifdef KERNEL
! register struct mbuf *m;
!
! if (buflen != 0)
! return 0;
! m = (struct mbuf *)p;
! MINDEX(m, k);
! A = mtod(m, char *)[k];
continue;
#else
return 0;
--- 309,317 ----
k = X + pc->k;
if (k >= buflen) {
#ifdef KERNEL
! n = m;
! MINDEX(n, k);
! A = mtod(n, char *)[k];
continue;
#else
return 0;
***************
*** 337,349 ****
k = pc->k;
if (k >= buflen) {
#ifdef KERNEL
! register struct mbuf *m;
!
! if (buflen != 0)
! return 0;
! m = (struct mbuf *)p;
! MINDEX(m, k);
! X = (mtod(m, char *)[k] & 0xf) << 2;
continue;
#else
return 0;
--- 324,332 ----
k = pc->k;
if (k >= buflen) {
#ifdef KERNEL
! n = m;
! MINDEX(n, k);
! X = (mtod(n, char *)[k] & 0xf) << 2;
continue;
#else
return 0;