summaryrefslogtreecommitdiffstats
path: root/sys/netipsec/ipsec_mbuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/netipsec/ipsec_mbuf.c')
-rw-r--r--sys/netipsec/ipsec_mbuf.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/sys/netipsec/ipsec_mbuf.c b/sys/netipsec/ipsec_mbuf.c
index 7111210..6617d48 100644
--- a/sys/netipsec/ipsec_mbuf.c
+++ b/sys/netipsec/ipsec_mbuf.c
@@ -30,8 +30,6 @@
* IPsec-specific mbuf routines.
*/
-#include "opt_param.h"
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
@@ -72,7 +70,21 @@ m_makespace(struct mbuf *m0, int skip, int hlen, int *off)
* the contents of m as needed.
*/
remain = m->m_len - skip; /* data to move */
- if (hlen > M_TRAILINGSPACE(m)) {
+ if (remain > skip &&
+ hlen + max_linkhdr < M_LEADINGSPACE(m)) {
+ /*
+ * mbuf has enough free space at the beginning.
+ * XXX: which operation is the most heavy - copying of
+ * possible several hundred of bytes or allocation
+ * of new mbuf? We can remove max_linkhdr check
+ * here, but it is possible that this will lead
+ * to allocation of new mbuf in Layer 2 code.
+ */
+ m->m_data -= hlen;
+ bcopy(mtodo(m, hlen), mtod(m, caddr_t), skip);
+ m->m_len += hlen;
+ *off = skip;
+ } else if (hlen > M_TRAILINGSPACE(m)) {
struct mbuf *n0, *n, **np;
int todo, len, done, alloc;
@@ -140,7 +152,7 @@ m_makespace(struct mbuf *m0, int skip, int hlen, int *off)
* so there's space to write the new header.
*/
bcopy(mtod(m, caddr_t) + skip,
- mtod(m, caddr_t) + skip + hlen, remain);
+ mtod(m, caddr_t) + skip + hlen, remain);
m->m_len += hlen;
*off = skip;
}
OpenPOWER on IntegriCloud