Changeset View
Changeset View
Standalone View
Standalone View
sys/net/bpf.c
Show First 20 Lines • Show All 2,384 Lines • ▼ Show 20 Lines | |||||
#ifdef BPF_JITTER | #ifdef BPF_JITTER | ||||
bf = bpf_jitter_enable != 0 ? d->bd_bfilter : NULL; | bf = bpf_jitter_enable != 0 ? d->bd_bfilter : NULL; | ||||
/* XXX We cannot handle multiple mbufs. */ | /* XXX We cannot handle multiple mbufs. */ | ||||
if (bf != NULL && m->m_next == NULL) | if (bf != NULL && m->m_next == NULL) | ||||
slen = (*(bf->func))(mtod(m, u_char *), pktlen, | slen = (*(bf->func))(mtod(m, u_char *), pktlen, | ||||
pktlen); | pktlen); | ||||
else | else | ||||
#endif | #endif | ||||
slen = bpf_filter(d->bd_rfilter, (u_char *)m, pktlen, 0); | slen = bpf_mfilter(d->bd_rfilter, m, pktlen); | ||||
if (slen != 0) { | if (slen != 0) { | ||||
BPFD_LOCK(d); | BPFD_LOCK(d); | ||||
counter_u64_add(d->bd_fcount, 1); | counter_u64_add(d->bd_fcount, 1); | ||||
if (gottime < bpf_ts_quality(d->bd_tstamp)) | if (gottime < bpf_ts_quality(d->bd_tstamp)) | ||||
gottime = bpf_gettime(&bt, d->bd_tstamp, m); | gottime = bpf_gettime(&bt, d->bd_tstamp, m); | ||||
#ifdef MAC | #ifdef MAC | ||||
if (mac_bpfdesc_check_receive(d, bp->bif_ifp) == 0) | if (mac_bpfdesc_check_receive(d, bp->bif_ifp) == 0) | ||||
Show All 40 Lines | bpf_mtap2(struct bpf_if *bp, void *data, u_int dlen, struct mbuf *m) | ||||
gottime = BPF_TSTAMP_NONE; | gottime = BPF_TSTAMP_NONE; | ||||
NET_EPOCH_ENTER(et); | NET_EPOCH_ENTER(et); | ||||
CK_LIST_FOREACH(d, &bp->bif_dlist, bd_next) { | CK_LIST_FOREACH(d, &bp->bif_dlist, bd_next) { | ||||
if (BPF_CHECK_DIRECTION(d, m->m_pkthdr.rcvif, bp->bif_ifp)) | if (BPF_CHECK_DIRECTION(d, m->m_pkthdr.rcvif, bp->bif_ifp)) | ||||
continue; | continue; | ||||
counter_u64_add(d->bd_rcount, 1); | counter_u64_add(d->bd_rcount, 1); | ||||
slen = bpf_filter(d->bd_rfilter, (u_char *)&mb, pktlen, 0); | slen = bpf_mfilter(d->bd_rfilter, &mb, pktlen); | ||||
if (slen != 0) { | if (slen != 0) { | ||||
BPFD_LOCK(d); | BPFD_LOCK(d); | ||||
counter_u64_add(d->bd_fcount, 1); | counter_u64_add(d->bd_fcount, 1); | ||||
if (gottime < bpf_ts_quality(d->bd_tstamp)) | if (gottime < bpf_ts_quality(d->bd_tstamp)) | ||||
gottime = bpf_gettime(&bt, d->bd_tstamp, m); | gottime = bpf_gettime(&bt, d->bd_tstamp, m); | ||||
#ifdef MAC | #ifdef MAC | ||||
if (mac_bpfdesc_check_receive(d, bp->bif_ifp) == 0) | if (mac_bpfdesc_check_receive(d, bp->bif_ifp) == 0) | ||||
▲ Show 20 Lines • Show All 614 Lines • ▼ Show 20 Lines | CK_LIST_FOREACH(bp, &bpf_iflist, bif_next) { | ||||
} | } | ||||
} | } | ||||
BPF_UNLOCK(); | BPF_UNLOCK(); | ||||
error = SYSCTL_OUT(req, xbdbuf, index * sizeof(*xbd)); | error = SYSCTL_OUT(req, xbdbuf, index * sizeof(*xbd)); | ||||
free(xbdbuf, M_BPF); | free(xbdbuf, M_BPF); | ||||
return (error); | return (error); | ||||
} | } | ||||
static u_int32_t bpf_mbuf_ldw(const void *, u_int32_t, int *); | |||||
static u_int32_t bpf_mbuf_ldh(const void *, u_int32_t, int *); | |||||
static u_int32_t bpf_mbuf_ldb(const void *, u_int32_t, int *); | |||||
static int bpf_mbuf_copy(const struct mbuf *, u_int32_t, void *, u_int32_t); | |||||
static const struct bpf_ops bpf_mbuf_ops = { | |||||
bpf_mbuf_ldw, | |||||
bpf_mbuf_ldh, | |||||
bpf_mbuf_ldb, | |||||
}; | |||||
static int | |||||
bpf_mbuf_copy(const struct mbuf *m, u_int32_t off, void *buf, u_int32_t len) | |||||
{ | |||||
u_int8_t *cp = buf; | |||||
u_int32_t count; | |||||
while (off >= m->m_len) { | |||||
off -= m->m_len; | |||||
m = m->m_next; | |||||
if (m == NULL) | |||||
return (-1); | |||||
} | |||||
for (;;) { | |||||
count = min(m->m_len - off, len); | |||||
memcpy(cp, m->m_data + off, count); | |||||
len -= count; | |||||
if (len == 0) | |||||
return (0); | |||||
m = m->m_next; | |||||
if (m == NULL) | |||||
break; | |||||
cp += count; | |||||
off = 0; | |||||
} | |||||
return (-1); | |||||
} | |||||
static u_int32_t | |||||
bpf_mbuf_ldw(const void *m0, u_int32_t k, int *err) | |||||
{ | |||||
u_int32_t v; | |||||
if (bpf_mbuf_copy(m0, k, &v, sizeof(v)) != 0) { | |||||
*err = 1; | |||||
return (0); | |||||
} | |||||
*err = 0; | |||||
return ntohl(v); | |||||
} | |||||
static u_int32_t | |||||
bpf_mbuf_ldh(const void *m0, u_int32_t k, int *err) | |||||
{ | |||||
u_int16_t v; | |||||
if (bpf_mbuf_copy(m0, k, &v, sizeof(v)) != 0) { | |||||
*err = 1; | |||||
return (0); | |||||
} | |||||
*err = 0; | |||||
return ntohs(v); | |||||
} | |||||
static u_int32_t | |||||
bpf_mbuf_ldb(const void *m0, u_int32_t k, int *err) | |||||
{ | |||||
const struct mbuf *m = m0; | |||||
u_int8_t v; | |||||
while (k >= m->m_len) { | |||||
k -= m->m_len; | |||||
m = m->m_next; | |||||
if (m == NULL) { | |||||
*err = 1; | |||||
return (0); | |||||
} | |||||
} | |||||
v = m->m_data[k]; | |||||
*err = 0; | |||||
return v; | |||||
} | |||||
u_int | |||||
bpf_mfilter(const struct bpf_insn *pc, const struct mbuf *m, u_int wirelen) | |||||
{ | |||||
return _bpf_filter(pc, &bpf_mbuf_ops, m, wirelen); | |||||
} | |||||
SYSINIT(bpfdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE,bpf_drvinit,NULL); | SYSINIT(bpfdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE,bpf_drvinit,NULL); | ||||
#else /* !DEV_BPF && !NETGRAPH_BPF */ | #else /* !DEV_BPF && !NETGRAPH_BPF */ | ||||
/* | /* | ||||
* NOP stubs to allow bpf-using drivers to load and function. | * NOP stubs to allow bpf-using drivers to load and function. | ||||
* | * | ||||
* A 'better' implementation would allow the core bpf functionality | * A 'better' implementation would allow the core bpf functionality | ||||
Show All 30 Lines | |||||
} | } | ||||
void | void | ||||
bpfdetach(struct ifnet *ifp) | bpfdetach(struct ifnet *ifp) | ||||
{ | { | ||||
} | } | ||||
u_int | u_int | ||||
bpf_filter(const struct bpf_insn *pc, u_char *p, u_int wirelen, u_int buflen) | bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen, u_int buflen) | ||||
{ | |||||
return -1; /* "no filter" behaviour */ | |||||
} | |||||
u_int | |||||
bpf_mfilter(const struct bpf_insn *pc, const struct mbuf *m, u_int wirelen) | |||||
{ | { | ||||
return -1; /* "no filter" behaviour */ | return -1; /* "no filter" behaviour */ | ||||
} | } | ||||
int | int | ||||
bpf_validate(const struct bpf_insn *f, int len) | bpf_validate(const struct bpf_insn *f, int len) | ||||
{ | { | ||||
return 0; /* false */ | return 0; /* false */ | ||||
Show All 35 Lines |