ML_INIT(9)

NAME
ml_init, ml_enqueue, ml_dequeue, ml_requeue, ml_dechain, ml_len, ml_empty, MBUF_LIST_INITIALIZER, MBUF_LIST_FOREACH, - mbuf list API

SYNOPSIS
#include <sys/mbuf.h>
ml_init(struct mbuf_list *ml);
void
ml_enqueue(struct mbuf_list *ml, struct mbuf *m);
struct mbuf *
ml_dequeue(struct mbuf_list *ml);
void
ml_requeue(struct mbuf_list *ml, struct mbuf *m);
struct mbuf *
ml_dechain(struct mbuf_list *ml);
struct mbuf *
ml_filter(struct mbuf_list *ml, int (*filter)(void *, struct mbuf *), void *context);
unsigned int
ml_len(struct mbuf_list *ml);
int
ml_empty(struct mbuf_list *ml);
struct mbuf_list
MBUF_LIST_INITIALIZER();
MBUF_LIST_FOREACH(struct mbuf_list *ml, VARNAME);

DESCRIPTION
The mbuf list API provides implementions of data structures and operations for managing lists of mbufs between contexts.

mbuf_list structures support the following functionality:

1.  Insertion of a new mbuf at the end of the list.
2.  Removal of an mbuf from the head of the list.
3.  Reinsertion of an mbuf at the head of the list.
4.  Removal of the entire chain of mbufs on the list.

ml_init(struct mbuf_list *ml)
    Initialise the ml mbuf_list structure.

MBUF_LIST_INITIALIZER()
    An initialiser for an mbuf_list structure declaration.

ml_enqueue(struct mbuf_list *ml, struct mbuf *m)
    Enqueue mbuf m on the end of the ml mbuf list.

ml_dequeue(struct mbuf_list *ml)
    Dequeue an mbuf from the front of the ml mbuf list.

ml_requeue(struct mbuf_list *ml, struct mbuf *m)
    Enqueue mbuf m at the head of the ml mbuf list.

ml_dechain(struct mbuf_list *ml)
    Dequeues all mbufs from the ml mbuf list.

ml_filter(
    struct mbuf_list *ml, int (*filter)(void *, struct mbuf *), void *context) Iterates over the mbufs on the ml mbuf list, passing each of them to the filter function. If the filter returns non-zero, the packet is removed from the ml mbuf list to be returned as part of an mbuf chain by ml_filter(). context is passed as the first argument to each call of filter.

ml_len(struct mbuf_list *ml)
    Return the number of mbufs on the ml mbuf list.

ml_empty(struct mbuf_list *ml)
    Return if the ml mbuf list is empty.

MBUF_LIST_FOREACH(struct mbuf_list *ml, VARNAME)
    A convenience macro that can be used to iterate over the contents of the ml mbuf list. VARNAME identifies the name (not the address) of an mbuf pointer that will be set to each entry on the list. Note that it is unsafe to modify the list while iterating over it.

CONTEXT
ml_init(), ml_enqueue(), ml_dequeue(), ml_requeue(), ml_dechain(), ml_len(), ml_empty(), MBUF_LIST_INITIALIZER(), and MBUF_LIST_FOREACH() can be called during autoconf, from process context, or from interrupt context.

RETURN VALUES
ml_dequeue() returns the mbuf that was at the head of its list. If the list was empty, NULL is returned.

ml_dechain() returns all the mbufs that were on the list via a pointer to an mbuf with the chain accessible via m_nextpkt members. If the list was empty, NULL is returned.

ml_filter() returns the mbufs that were successfully matched by the filter function on the list via a pointer to a chain of mbufs. If no packets matched the filter, NULL is returned.

ml_len() returns the number of mbufs on the list.

ml_empty() return a non-zero value if the list is empty, otherwise 0.

SEE ALSO
mbuf(9)