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
This commit is contained in:
Alexander Motin 2007-07-26 18:15:02 +00:00
parent 57fd3d5572
commit 091193febe
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=171600

View File

@ -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 *);