Remove inlined m_tag_free(). Rename _m_tag_free() to m_tag_free()

and make it visible (same way as in OpenBSD). Describe usage in manpage.

This change is useful for creating custom free methods, which
call default free method at their end.

While here, make malloc declaration for mbuf tags more informative.

Approved by:	julian (mentor), sam
MFC after:	1 month
This commit is contained in:
Gleb Smirnoff 2004-10-09 13:25:19 +00:00
parent 3b33d41dc2
commit 42c5607501
3 changed files with 23 additions and 22 deletions

View File

@ -91,8 +91,7 @@ fields are set to type, length,
and
cookie, respectively.
.Va m_tag_free
points to
.Xr free 9 .
points to a function which will be used to free this tag.
Following this structure are
.Va m_tag_len
bytes of space that can be used to store tag-specific information.
@ -194,11 +193,16 @@ Return the first tag associated with
.It Fn m_tag_free tag
Free
.Fa tag
using its
.Va m_tag_free
method.
.Xr free 9
is used by default.
using default free method.
This function should only be used at the end of a custom free method.
It should never be used to free a packet tag of an unknown origination.
To perform the latter
.Fn m_tag_delete
should be used in case of an attached
.Fa tag
or (tag->m_tag_free)(tag)
should be called in case of a detached
.Fa tag .
.It Fn m_tag_init mbuf
Initialize the tag storage for packet
.Fa mbuf .

View File

@ -76,7 +76,7 @@ __FBSDID("$FreeBSD$");
#include <sys/mbuf.h>
#include <sys/mutex.h>
MALLOC_DEFINE(M_PACKET_TAGS, "tag", "packet-attached information");
MALLOC_DEFINE(M_PACKET_TAGS, "mbuf tags", "packet-attached information");
/* can't call it m_dup(), as freebsd[34] uses m_dup() with different arg */
static struct mbuf *m_dup1(struct mbuf *, int, int, int);
@ -301,9 +301,14 @@ m_dup1(struct mbuf *m, int off, int len, int wait)
return n;
}
/* Free a packet tag. */
static void
_m_tag_free(struct m_tag *t)
/*
* Free a packet tag.
* This function should not be called directly, unless you know what you
* are doing. Use m_tag_delete() or (t->m_tag_free)(t) instead, when you
* work with a tag that you haven't allocated yourself.
*/
void
m_tag_free(struct m_tag *t)
{
#ifdef MAC
if (t->m_tag_id == PACKET_TAG_MACLABEL)
@ -325,7 +330,7 @@ m_tag_alloc(u_int32_t cookie, int type, int len, int wait)
if (t == NULL)
return NULL;
m_tag_setup(t, cookie, type, len);
t->m_tag_free = _m_tag_free;
t->m_tag_free = m_tag_free;
return t;
}
@ -336,7 +341,7 @@ m_tag_delete(struct mbuf *m, struct m_tag *t)
KASSERT(m && t, ("m_tag_delete: null argument, m %p t %p", m, t));
m_tag_unlink(m, t);
m_tag_free(t);
(t->m_tag_free)(t);
}
/* Unlink and free a packet tag chain, starting from given tag. */

View File

@ -648,6 +648,7 @@ struct mbuf *m_uiotombuf(struct uio *, int, int);
struct m_tag *m_tag_alloc(u_int32_t, int, int, int);
void m_tag_delete(struct mbuf *, struct m_tag *);
void m_tag_delete_chain(struct mbuf *, struct m_tag *);
void m_tag_free(struct m_tag *);
struct m_tag *m_tag_locate(struct mbuf *, u_int32_t, int, struct m_tag *);
struct m_tag *m_tag_copy(struct m_tag *, int);
int m_tag_copy_chain(struct mbuf *, struct mbuf *, int);
@ -677,15 +678,6 @@ m_tag_setup(struct m_tag *t, u_int32_t cookie, int type, int len)
t->m_tag_cookie = cookie;
}
/*
* Reclaim resources associated with a tag.
*/
static __inline void
m_tag_free(struct m_tag *t)
{
(*t->m_tag_free)(t);
}
/*
* Return the first tag associated with an mbuf.
*/