MCPcopy Create free account
hub / github.com/F-Stack/f-stack / m_pullup

Function m_pullup

freebsd/kern/uipc_mbuf.c:866–920  ·  view source on GitHub ↗

* Rearange 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. */

Source from the content-addressed store, hash-verified

864 * contiguous region in an attempt to avoid being called next time.
865 */
866struct mbuf *
867m_pullup(struct mbuf *n, int len)
868{
869 struct mbuf *m;
870 int count;
871 int space;
872
873 KASSERT((n->m_flags & M_EXTPG) == 0,
874 ("%s: unmapped mbuf %p", __func__, n));
875
876 /*
877 * If first mbuf has no cluster, and has room for len bytes
878 * without shifting current data, pullup into it,
879 * otherwise allocate a new mbuf to prepend to the chain.
880 */
881 if ((n->m_flags & M_EXT) == 0 &&
882 n->m_data + len < &n->m_dat[MLEN] && n->m_next) {
883 if (n->m_len >= len)
884 return (n);
885 m = n;
886 n = n->m_next;
887 len -= m->m_len;
888 } else {
889 if (len > MHLEN)
890 goto bad;
891 m = m_get(M_NOWAIT, n->m_type);
892 if (m == NULL)
893 goto bad;
894 if (n->m_flags & M_PKTHDR)
895 m_move_pkthdr(m, n);
896 }
897 space = &m->m_dat[MLEN] - (m->m_data + m->m_len);
898 do {
899 count = min(min(max(len, max_protohdr), space), n->m_len);
900 bcopy(mtod(n, caddr_t), mtod(m, caddr_t) + m->m_len,
901 (u_int)count);
902 len -= count;
903 m->m_len += count;
904 n->m_len -= count;
905 space -= count;
906 if (n->m_len)
907 n->m_data += count;
908 else
909 n = m_free(n);
910 } while (len > 0 && n);
911 if (len > 0) {
912 (void) m_free(m);
913 goto bad;
914 }
915 m->m_next = n;
916 return (m);
917bad:
918 m_freem(n);
919 return (NULL);
920}
921
922/*
923 * Like m_pullup(), except a new mbuf is always allocated, and we allow

Callers 15

ip_fil_freebsd.cFile · 0.85
pfsync_inputFunction · 0.85
ipfw_chkFunction · 0.85
dummynet_sendFunction · 0.85
nptv6_translate_icmpv6Function · 0.85
nat64clat_handle_icmp6Function · 0.85
inspect_icmp_mbufFunction · 0.85
nat64lsn_reassemble4Function · 0.85
nat64_icmp_translateFunction · 0.85
nat64_handle_icmp6Function · 0.85
nat64stl_handle_icmp6Function · 0.85
tcpmod_setmssFunction · 0.85

Calls 6

m_move_pkthdrFunction · 0.85
minFunction · 0.85
maxFunction · 0.85
m_freemFunction · 0.70
m_getFunction · 0.50
m_freeFunction · 0.50

Tested by

no test coverage detected