mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-15 10:17:20 +00:00
Changes and cleanups to m_sanity():
o for() instead of while() looping over mbuf chain o paren's around all flag checks o more verbose function and purpose description o some more style changes Based on feedback from: sam
This commit is contained in:
parent
e0068c3a69
commit
fdcc028d11
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=149648
@ -294,9 +294,11 @@ m_demote(struct mbuf *m0, int all)
|
||||
}
|
||||
|
||||
/*
|
||||
* Sanity checks on mbuf (chain).
|
||||
* Returns 0 bad, 1 good, panic worse.
|
||||
* sanitize, 0 run M_SANITY_ACTION, 1 garble things so they blow up later.
|
||||
* Sanity checks on mbuf (chain) for use in KASSERT() and general
|
||||
* debugging.
|
||||
* Returns 0 or panics when bad and 1 on all tests passed.
|
||||
* Sanitize, 0 to run M_SANITY_ACTION, 1 to garble things so they
|
||||
* blow up later.
|
||||
*/
|
||||
int
|
||||
m_sanity(struct mbuf *m0, int sanitize)
|
||||
@ -308,32 +310,31 @@ m_sanity(struct mbuf *m0, int sanitize)
|
||||
#define M_SANITY_ACTION(s) return (0)
|
||||
/* #define M_SANITY_ACTION(s) panic("mbuf %p: " s, m) */
|
||||
|
||||
m = m0;
|
||||
while (m) {
|
||||
for (m = m0; m != NULL; m = m->m_next) {
|
||||
/*
|
||||
* Basic pointer checks. If any of these fails then some
|
||||
* unrelated kernel memory before or after us is trashed.
|
||||
* No way to recover from that.
|
||||
*/
|
||||
a = (m->m_flags & M_EXT ? m->m_ext.ext_buf :
|
||||
(m->m_flags & M_PKTHDR ? (caddr_t)(&m->m_pktdat) :
|
||||
a = ((m->m_flags & M_EXT) ? m->m_ext.ext_buf :
|
||||
((m->m_flags & M_PKTHDR) ? (caddr_t)(&m->m_pktdat) :
|
||||
(caddr_t)(&m->m_dat)) );
|
||||
b = (caddr_t)(a + (m->m_flags & M_EXT ? m->m_ext.ext_size :
|
||||
(m->m_flags & M_PKTHDR ? MHLEN : MLEN)));
|
||||
((m->m_flags & M_PKTHDR) ? MHLEN : MLEN)));
|
||||
if ((caddr_t)m->m_data < a)
|
||||
M_SANITY_ACTION("m_data outside mbuf data range left");
|
||||
if ((caddr_t)m->m_data > b)
|
||||
M_SANITY_ACTION("m_data outside mbuf data range right");
|
||||
if ((caddr_t)m->m_data + m->m_len > b)
|
||||
M_SANITY_ACTION("m_data + m_len exeeds mbuf space");
|
||||
if (m->m_flags & M_PKTHDR && m->m_pkthdr.header) {
|
||||
if ((m->m_flags & M_PKTHDR) && m->m_pkthdr.header) {
|
||||
if ((caddr_t)m->m_pkthdr.header < a ||
|
||||
(caddr_t)m->m_pkthdr.header > b)
|
||||
M_SANITY_ACTION("m_pkthdr.header outside mbuf data range");
|
||||
}
|
||||
|
||||
/* m->m_nextpkt may only be set on first mbuf in chain. */
|
||||
if (m != m0 && m->m_nextpkt) {
|
||||
if (m != m0 && m->m_nextpkt != NULL) {
|
||||
if (sanitize) {
|
||||
m_freem(m->m_nextpkt);
|
||||
m->m_nextpkt = (struct mbuf *)0xDEADC0DE;
|
||||
@ -359,8 +360,7 @@ m_sanity(struct mbuf *m0, int sanitize)
|
||||
if (sanitize) {
|
||||
m_tag_delete_chain(m, NULL);
|
||||
/* put in 0xDEADC0DE perhaps? */
|
||||
}
|
||||
else
|
||||
} else
|
||||
M_SANITY_ACTION("m_tags on in-chain mbuf");
|
||||
}
|
||||
|
||||
@ -373,18 +373,17 @@ m_sanity(struct mbuf *m0, int sanitize)
|
||||
} else
|
||||
M_SANITY_ACTION("M_PKTHDR on in-chain mbuf");
|
||||
}
|
||||
|
||||
m = m->m_next;
|
||||
}
|
||||
if (pktlen && pktlen != m0->m_pkthdr.len) {
|
||||
m = m0;
|
||||
if (pktlen && pktlen != m->m_pkthdr.len) {
|
||||
if (sanitize)
|
||||
m0->m_pkthdr.len = 0;
|
||||
m->m_pkthdr.len = 0;
|
||||
else
|
||||
M_SANITY_ACTION("m_pkthdr.len != mbuf chain length");
|
||||
}
|
||||
#undef M_SANITY_ACTION
|
||||
|
||||
return 1;
|
||||
|
||||
#undef M_SANITY_ACTION
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user