Introduce an M_ASSERTPKTHDR() macro which performs the very common task

of asserting that an mbuf has a packet header.  Use it instead of hand-
rolled versions wherever applicable.

Submitted by:	Hiten Pandya <hiten@unixdaemons.com>
This commit is contained in:
Dag-Erling Smørgrav 2003-04-08 14:25:47 +00:00
parent 50d81222d8
commit fe58453891
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=113255
31 changed files with 52 additions and 66 deletions

View File

@ -667,8 +667,7 @@ bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map,
KASSERT(dmat->lowaddr >= ptoa(Maxmem) || map != NULL,
("bus_dmamap_load_mbuf: No support for bounce pages!"));
KASSERT(m0->m_flags & M_PKTHDR,
("bus_dmamap_load_mbuf: no packet header"));
M_ASSERTPKTHDR(m0);
nsegs = 0;
error = 0;

View File

@ -345,9 +345,7 @@ sncstart(ifp)
return;
/* We need the header for m_pkthdr.len. */
if ((m->m_flags & M_PKTHDR) == 0)
panic("%s: sncstart: no header mbuf",
device_get_nameunit(sc->sc_dev));
M_ASSERTPKTHDR(m);
/*
* If bpf is listening on this interface, let it

View File

@ -400,12 +400,9 @@ vxstart(ifp)
startagain:
/* Sneak a peek at the next packet */
m = ifp->if_snd.ifq_head;
if (m == NULL) {
return;
}
/* We need to use m->m_pkthdr.len, so require the header */
if ((m->m_flags & M_PKTHDR) == 0)
panic("vxstart: no header mbuf");
M_ASSERTPKTHDR(m);
len = m->m_pkthdr.len;
pad = (4 - len) & 3;

View File

@ -643,8 +643,7 @@ bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map,
KASSERT(dmat->lowaddr >= ptoa(Maxmem) || map != NULL,
("bus_dmamap_load_mbuf: No support for bounce pages!"));
KASSERT(m0->m_flags & M_PKTHDR,
("bus_dmamap_load_mbuf: no packet header"));
M_ASSERTPKTHDR(m0);
nsegs = 0;
error = 0;

View File

@ -721,7 +721,7 @@ mac_init_mbuf(struct mbuf *m, int flag)
{
int error;
KASSERT(m->m_flags & M_PKTHDR, ("mac_init_mbuf on non-header mbuf"));
M_ASSERTPKTHDR(m);
mac_init_label(&m->m_pkthdr.label);
@ -2270,7 +2270,7 @@ mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
if (!mac_enforce_network)
return (0);
KASSERT(mbuf->m_flags & M_PKTHDR, ("packet has no pkthdr"));
M_ASSERTPKTHDR(mbuf);
if (!(mbuf->m_pkthdr.label.l_flags & MAC_FLAG_INITIALIZED))
if_printf(ifnet, "not initialized\n");

View File

@ -87,8 +87,7 @@ m_move_pkthdr(struct mbuf *to, struct mbuf *from)
#if 0
/* see below for why these are not enabled */
KASSERT(to->m_flags & M_PKTHDR,
("m_move_pkthdr: called on non-header"));
M_ASSERTPKTHDR(to);
KASSERT(SLIST_EMPTY(&to->m_pkthdr.tags),
("m_move_pkthdr: to has tags"));
#endif
@ -125,7 +124,7 @@ m_dup_pkthdr(struct mbuf *to, struct mbuf *from, int how)
* smash the pkthdr as needed causing these
* assertions to trip. For now just disable them.
*/
KASSERT(to->m_flags & M_PKTHDR, ("m_dup_pkthdr: called on non-header"));
M_ASSERTPKTHDR(to);
KASSERT(SLIST_EMPTY(&to->m_pkthdr.tags), ("m_dup_pkthdr: to has tags"));
#endif
#ifdef MAC
@ -349,7 +348,7 @@ m_dup(struct mbuf *m, int how)
/* Sanity check */
if (m == NULL)
return (NULL);
KASSERT((m->m_flags & M_PKTHDR) != 0, ("%s: !PKTHDR", __func__));
M_ASSERTPKTHDR(m);
/* While there's more data, get a new mbuf, tack it on, and fill it */
remain = m->m_pkthdr.len;

View File

@ -155,8 +155,7 @@ static int
discoutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
struct rtentry *rt)
{
if ((m->m_flags & M_PKTHDR) == 0)
panic("discoutput no HDR");
M_ASSERTPKTHDR(m);
/* BPF write needs to be handled specially */
if (dst->sa_family == AF_UNSPEC) {
dst->sa_family = *(mtod(m, int *));

View File

@ -203,8 +203,7 @@ faithoutput(ifp, m, dst, rt)
{
int isr;
if ((m->m_flags & M_PKTHDR) == 0)
panic("faithoutput no HDR");
M_ASSERTPKTHDR(m);
/* BPF write needs to be handled specially */
if (dst->sa_family == AF_UNSPEC) {

View File

@ -192,8 +192,8 @@ looutput(ifp, m, dst, rt)
struct sockaddr *dst;
register struct rtentry *rt;
{
if ((m->m_flags & M_PKTHDR) == 0)
panic("looutput no HDR");
M_ASSERTPKTHDR(m); /* check if we have the packet header */
if (rt && rt->rt_flags & (RTF_REJECT|RTF_BLACKHOLE)) {
m_freem(m);
@ -276,7 +276,7 @@ if_simloop(ifp, m, af, hlen)
{
int isr;
KASSERT((m->m_flags & M_PKTHDR) != 0, ("if_simloop: no HDR"));
M_ASSERTPKTHDR(m);
m->m_pkthdr.rcvif = ifp;
/* BPF write needs to be handled specially */

View File

@ -451,8 +451,7 @@ ng_btsocket_hci_raw_data_input(struct mbuf *nam)
KASSERT((nam->m_type == MT_SONAME),
("%s: m_type=%d\n", __func__, nam->m_type));
KASSERT((m0->m_flags & M_PKTHDR),
("%s: m_flags=%#x\n", __func__, m0->m_flags));
M_ASSERTPKTHDR(m0);
sa = mtod(nam, struct sockaddr_hci *);
@ -614,8 +613,7 @@ ng_btsocket_hci_raw_output(node_p node, hook_p hook, void *arg1, int arg2)
KASSERT((nam->m_type == MT_SONAME),
("%s: m_type=%d\n", __func__, nam->m_type));
KASSERT((m->m_flags & M_PKTHDR),
("%s: m_flags=%#x\n", __func__, m->m_flags));
M_ASSERTPKTHDR(m);
sa = mtod(nam, struct sockaddr_hci *);

View File

@ -335,8 +335,7 @@ static ng_ID_t nextID = 1;
struct mbuf *n; \
int total; \
\
if (((m)->m_flags & M_PKTHDR) == 0) \
panic("%s: !PKTHDR", __func__); \
M_ASSERTPKTHDR(m); \
for (total = 0, n = (m); n != NULL; n = n->m_next) \
total += n->m_len; \
if ((m)->m_pkthdr.len != total) { \

View File

@ -739,7 +739,7 @@ ng_iface_rcvdata(hook_p hook, item_p item)
NG_FREE_ITEM(item);
/* Sanity checks */
KASSERT(iffam != NULL, ("%s: iffam", __func__));
KASSERT(m->m_flags & M_PKTHDR, ("%s: not pkthdr", __func__));
M_ASSERTPKTHDR(m);
if (m == NULL)
return (EINVAL);
if ((ifp->if_flags & IFF_UP) == 0) {

View File

@ -180,7 +180,7 @@ divert_packet(struct mbuf *m, int incoming, int port, int rule)
struct ifaddr *ifa;
/* Sanity check */
KASSERT((m->m_flags & M_PKTHDR), ("%s: !PKTHDR", __func__));
M_ASSERTPKTHDR(m);
/* Find IP address for receive interface */
TAILQ_FOREACH(ifa, &m->m_pkthdr.rcvif->if_addrhead, ifa_link) {

View File

@ -334,8 +334,7 @@ ip_input(struct mbuf *m)
}
}
KASSERT(m != NULL && (m->m_flags & M_PKTHDR) != 0,
("ip_input: no HDR"));
M_ASSERTPKTHDR(m);
if (args.rule) { /* dummynet already filtered us */
ip = mtod(m, struct ip *);

View File

@ -1827,8 +1827,7 @@ X_rsvp_input(struct mbuf *m, int off)
printf("rsvp_input: check vifs\n");
#ifdef DIAGNOSTIC
if (!(m->m_flags & M_PKTHDR))
panic("rsvp_input no hdr");
M_ASSERTPKTHDR(m);
#endif
ifp = m->m_pkthdr.rcvif;

View File

@ -199,7 +199,7 @@ ip_output(m0, opt, ro, flags, imo, inp)
}
m = m0;
KASSERT(!m || (m->m_flags & M_PKTHDR) != 0, ("ip_output: no HDR"));
M_ASSERTPKTHDR(m);
#ifndef FAST_IPSEC
KASSERT(ro != NULL, ("ip_output: no route, proto %d",
mtod(m, struct ip *)->ip_p));

View File

@ -114,8 +114,7 @@ key_output(m, va_alist)
}
}
if ((m->m_flags & M_PKTHDR) == 0)
panic("key_output: not M_PKTHDR ??");
M_ASSERTPKTHDR(m);
KEYDEBUG(KEYDEBUG_KEY_DUMP, kdebug_mbuf(m));

View File

@ -110,8 +110,7 @@ key_output(m, va_alist)
}
}
if ((m->m_flags & M_PKTHDR) == 0)
panic("key_output: not M_PKTHDR ??");
M_ASSERTPKTHDR(m);
KEYDEBUG(KEYDEBUG_KEY_DUMP, kdebug_mbuf(m));

View File

@ -705,8 +705,7 @@ natmintr(struct mbuf *m)
struct natmpcb *npcb;
#ifdef DIAGNOSTIC
if ((m->m_flags & M_PKTHDR) == 0)
panic("natmintr no HDR");
M_ASSERTPKTHDR(m);
#endif
npcb = (struct natmpcb *) m->m_pkthdr.rcvif; /* XXX: overloaded */

View File

@ -417,8 +417,7 @@ bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map, struct mbuf *m0,
#endif
int nsegs = 0, error = 0;
KASSERT(m0->m_flags & M_PKTHDR,
("bus_dmamap_load_mbuf: no packet header"));
M_ASSERTPKTHDR(m0);
if (m0->m_pkthdr.len <= dmat->maxsize) {
int first = 1;

View File

@ -721,7 +721,7 @@ mac_init_mbuf(struct mbuf *m, int flag)
{
int error;
KASSERT(m->m_flags & M_PKTHDR, ("mac_init_mbuf on non-header mbuf"));
M_ASSERTPKTHDR(m);
mac_init_label(&m->m_pkthdr.label);
@ -2270,7 +2270,7 @@ mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
if (!mac_enforce_network)
return (0);
KASSERT(mbuf->m_flags & M_PKTHDR, ("packet has no pkthdr"));
M_ASSERTPKTHDR(mbuf);
if (!(mbuf->m_pkthdr.label.l_flags & MAC_FLAG_INITIALIZED))
if_printf(ifnet, "not initialized\n");

View File

@ -721,7 +721,7 @@ mac_init_mbuf(struct mbuf *m, int flag)
{
int error;
KASSERT(m->m_flags & M_PKTHDR, ("mac_init_mbuf on non-header mbuf"));
M_ASSERTPKTHDR(m);
mac_init_label(&m->m_pkthdr.label);
@ -2270,7 +2270,7 @@ mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
if (!mac_enforce_network)
return (0);
KASSERT(mbuf->m_flags & M_PKTHDR, ("packet has no pkthdr"));
M_ASSERTPKTHDR(mbuf);
if (!(mbuf->m_pkthdr.label.l_flags & MAC_FLAG_INITIALIZED))
if_printf(ifnet, "not initialized\n");

View File

@ -721,7 +721,7 @@ mac_init_mbuf(struct mbuf *m, int flag)
{
int error;
KASSERT(m->m_flags & M_PKTHDR, ("mac_init_mbuf on non-header mbuf"));
M_ASSERTPKTHDR(m);
mac_init_label(&m->m_pkthdr.label);
@ -2270,7 +2270,7 @@ mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
if (!mac_enforce_network)
return (0);
KASSERT(mbuf->m_flags & M_PKTHDR, ("packet has no pkthdr"));
M_ASSERTPKTHDR(mbuf);
if (!(mbuf->m_pkthdr.label.l_flags & MAC_FLAG_INITIALIZED))
if_printf(ifnet, "not initialized\n");

View File

@ -721,7 +721,7 @@ mac_init_mbuf(struct mbuf *m, int flag)
{
int error;
KASSERT(m->m_flags & M_PKTHDR, ("mac_init_mbuf on non-header mbuf"));
M_ASSERTPKTHDR(m);
mac_init_label(&m->m_pkthdr.label);
@ -2270,7 +2270,7 @@ mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
if (!mac_enforce_network)
return (0);
KASSERT(mbuf->m_flags & M_PKTHDR, ("packet has no pkthdr"));
M_ASSERTPKTHDR(mbuf);
if (!(mbuf->m_pkthdr.label.l_flags & MAC_FLAG_INITIALIZED))
if_printf(ifnet, "not initialized\n");

View File

@ -721,7 +721,7 @@ mac_init_mbuf(struct mbuf *m, int flag)
{
int error;
KASSERT(m->m_flags & M_PKTHDR, ("mac_init_mbuf on non-header mbuf"));
M_ASSERTPKTHDR(m);
mac_init_label(&m->m_pkthdr.label);
@ -2270,7 +2270,7 @@ mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
if (!mac_enforce_network)
return (0);
KASSERT(mbuf->m_flags & M_PKTHDR, ("packet has no pkthdr"));
M_ASSERTPKTHDR(mbuf);
if (!(mbuf->m_pkthdr.label.l_flags & MAC_FLAG_INITIALIZED))
if_printf(ifnet, "not initialized\n");

View File

@ -721,7 +721,7 @@ mac_init_mbuf(struct mbuf *m, int flag)
{
int error;
KASSERT(m->m_flags & M_PKTHDR, ("mac_init_mbuf on non-header mbuf"));
M_ASSERTPKTHDR(m);
mac_init_label(&m->m_pkthdr.label);
@ -2270,7 +2270,7 @@ mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
if (!mac_enforce_network)
return (0);
KASSERT(mbuf->m_flags & M_PKTHDR, ("packet has no pkthdr"));
M_ASSERTPKTHDR(mbuf);
if (!(mbuf->m_pkthdr.label.l_flags & MAC_FLAG_INITIALIZED))
if_printf(ifnet, "not initialized\n");

View File

@ -721,7 +721,7 @@ mac_init_mbuf(struct mbuf *m, int flag)
{
int error;
KASSERT(m->m_flags & M_PKTHDR, ("mac_init_mbuf on non-header mbuf"));
M_ASSERTPKTHDR(m);
mac_init_label(&m->m_pkthdr.label);
@ -2270,7 +2270,7 @@ mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
if (!mac_enforce_network)
return (0);
KASSERT(mbuf->m_flags & M_PKTHDR, ("packet has no pkthdr"));
M_ASSERTPKTHDR(mbuf);
if (!(mbuf->m_pkthdr.label.l_flags & MAC_FLAG_INITIALIZED))
if_printf(ifnet, "not initialized\n");

View File

@ -721,7 +721,7 @@ mac_init_mbuf(struct mbuf *m, int flag)
{
int error;
KASSERT(m->m_flags & M_PKTHDR, ("mac_init_mbuf on non-header mbuf"));
M_ASSERTPKTHDR(m);
mac_init_label(&m->m_pkthdr.label);
@ -2270,7 +2270,7 @@ mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *mbuf)
if (!mac_enforce_network)
return (0);
KASSERT(mbuf->m_flags & M_PKTHDR, ("packet has no pkthdr"));
M_ASSERTPKTHDR(mbuf);
if (!(mbuf->m_pkthdr.label.l_flags & MAC_FLAG_INITIALIZED))
if_printf(ifnet, "not initialized\n");

View File

@ -446,8 +446,7 @@ nexus_dmamap_load_mbuf(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat,
#endif
int nsegs, error;
KASSERT(m0->m_flags & M_PKTHDR,
("nexus_dmamap_load_mbuf: no packet header"));
M_ASSERTPKTHDR(m0);
nsegs = 0;
error = 0;

View File

@ -906,8 +906,7 @@ iommu_dvmamap_load_mbuf(bus_dma_tag_t pt, bus_dma_tag_t dt,
struct mbuf *m;
int error = 0, first = 1, nsegs = -1;
KASSERT(m0->m_flags & M_PKTHDR,
("iommu_dvmamap_load_mbuf: no packet header"));
M_ASSERTPKTHDR(m0);
if (map->dm_loaded) {
#ifdef DIAGNOSTIC

View File

@ -333,6 +333,13 @@ struct mbstat {
#define M_WRITABLE(m) (!((m)->m_flags & M_RDONLY) && (!((m)->m_flags \
& M_EXT) || !MEXT_IS_REF(m)))
/*
* Check if the supplied mbuf has a packet header, or else panic.
*/
#define M_ASSERTPKTHDR(m) \
KASSERT(m != NULL && m->m_flags & M_PKTHDR, \
("%s: no mbuf packet header!", __func__))
/*
* Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place
* an object of the specified size at the end of the mbuf, longword aligned.