diff options
author | Bret Lambert <blambert@cvs.openbsd.org> | 2011-05-04 16:05:50 +0000 |
---|---|---|
committer | Bret Lambert <blambert@cvs.openbsd.org> | 2011-05-04 16:05:50 +0000 |
commit | 5f848fb5f2f55c199db2de8dfe5d9e5ef6c8ff11 (patch) | |
tree | bca9d9b5c4ab3e082c07cc2014c2ccb94db8ad27 /sys | |
parent | 59a218178fb54575bf5b30819c39cb1f242e2b65 (diff) |
Collapse m_pullup and m_pullup2 into a single function, as they're
essentially identical; the only difference being that m_pullup2 is
capable of handling mbuf clusters, but called m_pullup for shorter
lengths (!).
testing dlg@ ok claudio@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/uipc_mbuf.c | 93 | ||||
-rw-r--r-- | sys/net/if_spppsubr.c | 4 | ||||
-rw-r--r-- | sys/net80211/ieee80211_pae_input.c | 4 | ||||
-rw-r--r-- | sys/netinet/ip_carp.c | 4 | ||||
-rw-r--r-- | sys/netinet/udp_usrreq.c | 4 | ||||
-rw-r--r-- | sys/sys/mbuf.h | 3 |
6 files changed, 24 insertions, 88 deletions
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index 221109171a9..24f877c607f 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_mbuf.c,v 1.156 2011/04/18 19:23:46 art Exp $ */ +/* $OpenBSD: uipc_mbuf.c,v 1.157 2011/05/04 16:05:49 blambert Exp $ */ /* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */ /* @@ -917,20 +917,16 @@ m_adj(struct mbuf *mp, int req_len) } /* - * Rearange an mbuf chain so that len bytes are contiguous - * and in the data area of an mbuf (so that mtod and dtom - * will work for a structure of size len). Returns the resulting + * Rearrange an mbuf chain so that len bytes are contiguous + * and in the data area of an mbuf (so that mtod will work + * for a structure of size len). Returns the resulting * mbuf chain on success, frees it and returns null on failure. - * If there is room, it will add up to max_protohdr-len extra bytes to the - * contiguous region in an attempt to avoid being called next time. */ -struct mbuf * -m_pullup(struct mbuf *n, int len) +struct mbuf * +m_pullup(struct mbuf *n, int len) { struct mbuf *m; int count; - int space; - int s; /* * If first mbuf has no cluster, and has room for len bytes @@ -944,62 +940,7 @@ m_pullup(struct mbuf *n, int len) m = n; n = n->m_next; len -= m->m_len; - } else { - if (len > MHLEN) - goto bad; - MGET(m, M_DONTWAIT, n->m_type); - if (m == NULL) - goto bad; - m->m_len = 0; - if (n->m_flags & M_PKTHDR) - M_MOVE_PKTHDR(m, n); - } - space = &m->m_dat[MLEN] - (m->m_data + m->m_len); - s = splnet(); - do { - count = min(min(max(len, max_protohdr), space), n->m_len); - bcopy(mtod(n, caddr_t), mtod(m, caddr_t) + m->m_len, - (unsigned)count); - len -= count; - m->m_len += count; - n->m_len -= count; - space -= count; - if (n->m_len) - n->m_data += count; - else - n = m_free_unlocked(n); - } while (len > 0 && n); - if (len > 0) { - (void)m_free_unlocked(m); - splx(s); - goto bad; - } - splx(s); - m->m_next = n; - return (m); -bad: - m_freem(n); - return (NULL); -} - -/* - * m_pullup2() works like m_pullup, save that len can be <= MCLBYTES. - * m_pullup2() only works on values of len such that MHLEN < len <= MCLBYTES, - * it calls m_pullup() for values <= MHLEN. It also only coagulates the - * requested number of bytes. (For those of us who expect unwieldy option - * headers. - * - * KEBE SAYS: Remember that dtom() calls with data in clusters does not work! - */ -struct mbuf * -m_pullup2(struct mbuf *n, int len) -{ - struct mbuf *m; - int count; - - if (len <= MHLEN) - return m_pullup(n, len); - if ((n->m_flags & M_EXT) != 0 && + } else if ((n->m_flags & M_EXT) != 0 && len > MHLEN && n->m_data + len < &n->m_data[MCLBYTES] && n->m_next) { if (n->m_len >= len) return (n); @@ -1012,20 +953,16 @@ m_pullup2(struct mbuf *n, int len) MGET(m, M_DONTWAIT, n->m_type); if (m == NULL) goto bad; - MCLGET(m, M_DONTWAIT); - if ((m->m_flags & M_EXT) == 0) { - m_free(m); - goto bad; + if (len > MHLEN) { + MCLGET(m, M_DONTWAIT); + if ((m->m_flags & M_EXT) == 0) { + m_free(m); + goto bad; + } } m->m_len = 0; - if (n->m_flags & M_PKTHDR) { - /* Too many adverse side effects. */ - /* M_MOVE_PKTHDR(m, n); */ - m->m_flags = (n->m_flags & M_COPYFLAGS) | - M_EXT | M_CLUSTER; - M_MOVE_HDR(m, n); - /* n->m_data is cool. */ - } + if (n->m_flags & M_PKTHDR) + M_MOVE_PKTHDR(m, n); } do { diff --git a/sys/net/if_spppsubr.c b/sys/net/if_spppsubr.c index b02368ecfd2..99d4dcc23db 100644 --- a/sys/net/if_spppsubr.c +++ b/sys/net/if_spppsubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_spppsubr.c,v 1.85 2011/04/17 20:44:27 stsp Exp $ */ +/* $OpenBSD: if_spppsubr.c,v 1.86 2011/05/04 16:05:49 blambert Exp $ */ /* * Synchronous PPP/Cisco link level subroutines. * Keepalive protocol implemented in both Cisco and PPP modes. @@ -540,7 +540,7 @@ sppp_input(struct ifnet *ifp, struct mbuf *m) /* preserve the alignment */ if (m->m_len < m->m_pkthdr.len) { - m = m_pullup2(m, m->m_pkthdr.len); + m = m_pullup(m, m->m_pkthdr.len); if (m == NULL) { if (debug) log(LOG_DEBUG, diff --git a/sys/net80211/ieee80211_pae_input.c b/sys/net80211/ieee80211_pae_input.c index 9d97d72bbfb..3dfcbce8fe7 100644 --- a/sys/net80211/ieee80211_pae_input.c +++ b/sys/net80211/ieee80211_pae_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ieee80211_pae_input.c,v 1.17 2010/02/06 15:16:27 jcs Exp $ */ +/* $OpenBSD: ieee80211_pae_input.c,v 1.18 2011/05/04 16:05:49 blambert Exp $ */ /*- * Copyright (c) 2007,2008 Damien Bergamini <damien.bergamini@free.fr> @@ -141,7 +141,7 @@ ieee80211_eapol_key_input(struct ieee80211com *ic, struct mbuf *m, } /* make sure the key data field is contiguous */ - if (m->m_len < totlen && (m = m_pullup2(m, totlen)) == NULL) { + if (m->m_len < totlen && (m = m_pullup(m, totlen)) == NULL) { ic->ic_stats.is_rx_nombuf++; goto done; } diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index 18612047086..7c1722d23cb 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_carp.c,v 1.183 2011/04/29 12:36:31 mpf Exp $ */ +/* $OpenBSD: ip_carp.c,v 1.184 2011/05/04 16:05:49 blambert Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff. All rights reserved. @@ -591,7 +591,7 @@ carp_proto_input(struct mbuf *m, ...) return; } - if ((m = m_pullup2(m, len)) == NULL) { + if ((m = m_pullup(m, len)) == NULL) { carpstats.carps_hdrops++; return; } diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 58e0a040ec1..53906eece24 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.142 2011/04/28 09:56:27 claudio Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.143 2011/05/04 16:05:49 blambert Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -352,7 +352,7 @@ udp_input(struct mbuf *m, ...) * to userland */ if (spi != 0) { - if ((m = m_pullup2(m, skip)) == NULL) { + if ((m = m_pullup(m, skip)) == NULL) { udpstat.udps_hdrops++; return; } diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 203822a3460..eda8eb81e41 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mbuf.h,v 1.151 2011/04/24 19:36:54 bluhm Exp $ */ +/* $OpenBSD: mbuf.h,v 1.152 2011/05/04 16:05:49 blambert Exp $ */ /* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */ /* @@ -403,7 +403,6 @@ int m_defrag(struct mbuf *, int); struct mbuf *m_prepend(struct mbuf *, int, int); struct mbuf *m_pulldown(struct mbuf *, int, int, int *); struct mbuf *m_pullup(struct mbuf *, int); -struct mbuf *m_pullup2(struct mbuf *, int); struct mbuf *m_split(struct mbuf *, int, int); struct mbuf *m_inject(struct mbuf *, int, int, int); struct mbuf *m_getptr(struct mbuf *, int, int *); |