diff options
author | Mike Belopuhov <mikeb@cvs.openbsd.org> | 2010-09-23 16:34:10 +0000 |
---|---|---|
committer | Mike Belopuhov <mikeb@cvs.openbsd.org> | 2010-09-23 16:34:10 +0000 |
commit | 6866f56672456f72b87687f9c41628c5f78cd947 (patch) | |
tree | 80f755389005687e4737a49f9f9b118bed48e1bb /sys/netinet/ip_esp.c | |
parent | ce1f4a5f6f3a33c84387cf640fab528621e8ded8 (diff) |
remove m_pad in favor of m_inject as it's equivalent to m_inject
with an offset equal to the actual data length.
ok henning blambert
Diffstat (limited to 'sys/netinet/ip_esp.c')
-rw-r--r-- | sys/netinet/ip_esp.c | 82 |
1 files changed, 5 insertions, 77 deletions
diff --git a/sys/netinet/ip_esp.c b/sys/netinet/ip_esp.c index 240f9747aae..d16c0e0afec 100644 --- a/sys/netinet/ip_esp.c +++ b/sys/netinet/ip_esp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_esp.c,v 1.112 2010/09/22 13:40:05 mikeb Exp $ */ +/* $OpenBSD: ip_esp.c,v 1.113 2010/09/23 16:33:48 mikeb Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr) and @@ -932,12 +932,13 @@ esp_output(struct mbuf *m, struct tdb *tdb, struct mbuf **mp, int skip, * Add padding -- better to do it ourselves than use the crypto engine, * although if/when we support compression, we'd have to do that. */ - pad = (u_char *) m_pad(m, padding + alen); - if (pad == NULL) { - DPRINTF(("esp_output(): m_pad() failed for SA %s/%08x\n", + mo = m_inject(m, m->m_pkthdr.len, padding + alen, M_DONTWAIT); + if (mo == NULL) { + DPRINTF(("esp_output(): m_inject failed for SA %s/%08x\n", ipsp_address(tdb->tdb_dst), ntohl(tdb->tdb_spi))); return ENOBUFS; } + pad = mtod(mo, u_char *); /* Self-describing or random padding ? */ if (!(tdb->tdb_flags & TDBF_RANDOMPADDING)) @@ -1179,76 +1180,3 @@ checkreplaywindow32(u_int32_t seq, u_int32_t initial, u_int32_t *lastseq, *bitmap |= (((u_int32_t) 1) << diff); return 0; } - -/* - * m_pad(m, n) pads <m> with <n> bytes at the end. The packet header - * length is updated, and a pointer to the first byte of the padding - * (which is guaranteed to be all in one mbuf) is returned. - */ - -caddr_t -m_pad(struct mbuf *m, int n) -{ - struct mbuf *m0, *m1; - int len, pad; - caddr_t retval; - - if (n <= 0) { /* No stupid arguments. */ - DPRINTF(("m_pad(): pad length invalid (%d)\n", n)); - m_freem(m); - return NULL; - } - - len = m->m_pkthdr.len; - pad = n; - m0 = m; - - while (m0->m_len < len) { - len -= m0->m_len; - m0 = m0->m_next; - } - - if (m0->m_len != len) { - DPRINTF(("m_pad(): length mismatch (should be %d instead of " - "%d)\n", m->m_pkthdr.len, - m->m_pkthdr.len + m0->m_len - len)); - - m_freem(m); - return NULL; - } - - /* Check for zero-length trailing mbufs, and find the last one. */ - for (m1 = m0; m1->m_next; m1 = m1->m_next) { - if (m1->m_next->m_len != 0) { - DPRINTF(("m_pad(): length mismatch (should be %d " - "instead of %d)\n", m->m_pkthdr.len, - m->m_pkthdr.len + m1->m_next->m_len)); - - m_freem(m); - return NULL; - } - - m0 = m1->m_next; - } - - if ((m0->m_flags & M_EXT) || - m0->m_data + m0->m_len + pad >= &(m0->m_dat[MLEN])) { - /* Add an mbuf to the chain. */ - MGET(m1, M_DONTWAIT, MT_DATA); - if (m1 == 0) { - m_freem(m0); - DPRINTF(("m_pad(): cannot append\n")); - return NULL; - } - - m0->m_next = m1; - m0 = m1; - m0->m_len = 0; - } - - retval = m0->m_data + m0->m_len; - m0->m_len += pad; - m->m_pkthdr.len += pad; - - return retval; -} |