1 .\" $OpenBSD: mbuf_tags.9,v 1.18 2003/12/08 07:07:35 mcbride Exp $
3 .\" The authors of this manual page are Angelos D. Keromytis
4 .\" (angelos@cis.upenn.edu), Gleb Smirnoff <glebius@cell.sick.ru>, and
5 .\" Robert Watson <rwatson@FreeBSD.org>
7 .\" Copyright (c) 2004 Robert N. M. Watson
8 .\" Copyright (c) 2001 Angelos D. Keromytis
10 .\" Permission to use, copy, and modify this software with or without
11 .\" fee is hereby granted, provided that this entire notice is included
12 .\" in all source code copies of any software which is or includes a copy
13 .\" or modification of this software.
15 .\" THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
16 .\" IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
17 .\" REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
18 .\" MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
28 .Nd a framework for generic packet attributes
32 .Fn m_tag_alloc "u_int32_t cookie" "int type" "int len" "int wait"
34 .Fn m_tag_copy "struct m_tag *t" "int how"
36 .Fn m_tag_copy_chain "struct mbuf *to" "struct mbuf *from" "int how"
38 .Fn m_tag_delete "struct mbuf *m" "struct m_tag *t"
40 .Fn m_tag_delete_chain "struct mbuf *m" "struct m_tag *t"
42 .Fn m_tag_delete_nonpersistent "struct mbuf *m"
44 .Fn m_tag_find "struct mbuf *m" "int type" "struct m_tag *start"
46 .Fn m_tag_first "struct mbuf *m"
48 .Fn m_tag_free "struct m_tag *t"
50 .Fn m_tag_get "int type" "int len" "int wait"
52 .Fn m_tag_init "struct mbuf *m"
54 .Fn m_tag_locate "struct mbuf *m" "u_int32_t cookie" "int type" "struct m_tag *t"
56 .Fn m_tag_next "struct mbuf *m" "struct m_tag *t"
58 .Fn m_tag_prepend "struct mbuf *m" "struct m_tag *t"
60 .Fn m_tag_unlink "struct mbuf *m" "struct m_tag *t"
62 Mbuf tags allow additional meta-data to be associated with in-flight packets
63 by providing a mechanism for the tagging of additional kernel memory onto
65 Tags are maintained in chains off of the
67 header, and maintained using a series of API calls to allocate, search, and
69 Tags are identified using an ID and cookie that uniquely identify a class
70 of data tagged onto the packet, and may contain an arbitrary amount of
72 Typical uses of mbuf tags include the storage of VLAN tags as described in
74 Mandatory Access Control (MAC) labels as described in
76 IPsec policy information as described in
78 and packet filter tags used by
81 Tags will be maintained across a variety of operations, including the copying
82 of packet headers using facilities such as
86 Any tags associated with an mbuf header will be automatically freed when the
87 mbuf is freed, although some subsystems will wish to delete the tags prior
90 Packet tags are used by different kernel APIs
91 to keep track of operations done or
92 scheduled to happen to packets.
93 Each packet tag can be distinguished by its type and cookie.
94 The cookie is used to identify a specific module or API.
95 The packet tags are attached to mbuf packet headers.
98 .Fn sizeof "struct m_tag"
99 bytes of a tag contain a
103 SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */
104 u_int16_t m_tag_id; /* Tag ID */
105 u_int16_t m_tag_len; /* Length of data */
106 u_int32_t m_tag_cookie; /* ABI/Module ID */
107 void (*m_tag_free)(struct m_tag *);
113 field is used to link tags together (see
117 .Va m_tag_id , m_tag_len
120 fields are set to type, length,
122 cookie, respectively.
125 .Fn m_tag_free_default .
126 Following this structure are
128 bytes of space that can be used to store tag-specific information.
129 Addressing this data region may be tricky.
130 A safe way is embedding
132 into a private data structure, as follows:
133 .Bd -literal -offset indent
138 struct foo *p = (struct foo *)m_tag_alloc(...);
139 struct m_tag *mtag = &p->tag;
144 does not support cookies, it needs
146 to be globally unique.
147 To keep compatibility with
151 is provided along with some compatibility functions.
154 compatible code, one should be careful not to take already
156 Tag types are defined in
158 .Ss Packet Tag Manipulation Functions
159 .Bl -ohang -offset indent
160 .It Fn m_tag_alloc cookie type len wait
161 Allocate a new tag of type
167 bytes of space following the tag header itself.
170 argument is passed directly to
174 returns a memory buffer of
175 .Pq Va len No + Fn sizeof "struct m_tag"
180 A compatibility function
183 .It Fn m_tag_copy tag how
188 argument is passed directly to
190 The return values are the same as in
192 .It Fn m_tag_copy_chain tombuf frommbuf how
193 Allocate and copy all tags from mbuf
197 Returns 1 on success, and 0 on failure.
198 In the latter case, mbuf
200 loses all its tags, even previously present.
201 .It Fn m_tag_delete mbuf tag
207 .It Fn m_tag_delete_chain mbuf tag
208 Remove and free a packet tag chain, starting from
214 all tags are deleted.
215 .It Fn m_tag_delete_nonpersistent mbuf
218 tags and delete those which do not have the
221 .It Fn m_tag_first mbuf
222 Return the first tag associated with
224 .It Fn m_tag_free tag
231 .Fn m_tag_free_default
234 .It Fn m_tag_init mbuf
235 Initialize the tag storage for packet
237 .It Fn m_tag_locate mbuf cookie type tag
238 Search for a tag defined by
244 starting from position specified by
248 then search through the whole list.
249 Upon success, a pointer to the first found tag is returned.
253 A compatibility function
256 .It Fn m_tag_next mbuf tag
264 .It Fn m_tag_prepend mbuf tag
267 at the head of the tag list for packet
269 .It Fn m_tag_unlink mbuf tag
272 from the list of tags of packet
276 The tag-manipulating code is contained in the file
277 .Pa sys/kern/uipc_mbuf2.c .
278 Inlined functions are defined in
284 The packet tags first appeared in
287 .An Angelos D. Keromytis Aq angelos@openbsd.org .