From 091193febefe3e51213bd05d200c095fc1b14b7c Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Thu, 26 Jul 2007 18:15:02 +0000 Subject: [PATCH] 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 --- sys/netgraph/ng_bpf.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/sys/netgraph/ng_bpf.c b/sys/netgraph/ng_bpf.c index 0a006aea44c..2a3bbb5d538 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 *);