summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/ng_bpf.c
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2007-07-26 18:15:02 +0000
committermav <mav@FreeBSD.org>2007-07-26 18:15:02 +0000
commit5a9e4eaaa3f6fde8048d1731fdba6b1b30886414 (patch)
tree3463a9535340fd5c3e68f26466c12d1e6fde703b /sys/netgraph/ng_bpf.c
parentfe74e944d12452785490f4343dd388287bc64da4 (diff)
downloadFreeBSD-src-5a9e4eaaa3f6fde8048d1731fdba6b1b30886414.zip
FreeBSD-src-5a9e4eaaa3f6fde8048d1731fdba6b1b30886414.tar.gz
Reduce stack usage by 256 bytes per call. It helps to avoid kernel
stack overflow in complicated traffic filtering setups. There can be minor performance degradation for the MHLEN < len <= 256 case due to additional buffer allocation, but it is a rare case. Approved by: re (rwatson), glebius (mentor) MFC after: 1 week
Diffstat (limited to 'sys/netgraph/ng_bpf.c')
-rw-r--r--sys/netgraph/ng_bpf.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/sys/netgraph/ng_bpf.c b/sys/netgraph/ng_bpf.c
index 0a006ae..2a3bbb5 100644
--- a/sys/netgraph/ng_bpf.c
+++ b/sys/netgraph/ng_bpf.c
@@ -382,7 +382,7 @@ ng_bpf_rcvdata(hook_p hook, item_p item)
const hinfo_p hip = NG_HOOK_PRIVATE(hook);
int totlen;
int needfree = 0, error = 0;
- u_char *data, buf[256];
+ u_char *data;
hinfo_p dhip;
hook_p dest;
u_int len;
@@ -398,16 +398,22 @@ ng_bpf_rcvdata(hook_p hook, item_p item)
/* Need to put packet in contiguous memory for bpf */
if (m->m_next != NULL) {
- if (totlen > sizeof(buf)) {
+ if (totlen > MHLEN) {
MALLOC(data, u_char *, totlen, M_NETGRAPH_BPF, M_NOWAIT);
if (data == NULL) {
NG_FREE_ITEM(item);
return (ENOMEM);
}
needfree = 1;
- } else
- data = buf;
- m_copydata(m, 0, totlen, (caddr_t)data);
+ m_copydata(m, 0, totlen, (caddr_t)data);
+ } else {
+ NGI_M(item) = m = m_pullup(m, totlen);
+ if (m == NULL) {
+ NG_FREE_ITEM(item);
+ return (ENOBUFS);
+ }
+ data = mtod(m, u_char *);
+ }
} else
data = mtod(m, u_char *);
OpenPOWER on IntegriCloud