diff options
Diffstat (limited to 'src/lib/libc/net/inet6_option_space.3')
-rw-r--r-- | src/lib/libc/net/inet6_option_space.3 | 434 |
1 files changed, 434 insertions, 0 deletions
diff --git a/src/lib/libc/net/inet6_option_space.3 b/src/lib/libc/net/inet6_option_space.3 new file mode 100644 index 0000000000..9b5cac95e8 --- /dev/null +++ b/src/lib/libc/net/inet6_option_space.3 | |||
@@ -0,0 +1,434 @@ | |||
1 | .\" $OpenBSD: inet6_option_space.3,v 1.15 2005/01/06 03:50:46 itojun Exp $ | ||
2 | .\" $KAME: inet6_option_space.3,v 1.11 2005/01/05 03:00:44 itojun Exp $ | ||
3 | .\" | ||
4 | .\" Copyright (C) 2004 WIDE Project. | ||
5 | .\" All rights reserved. | ||
6 | .\" | ||
7 | .\" Redistribution and use in source and binary forms, with or without | ||
8 | .\" modification, are permitted provided that the following conditions | ||
9 | .\" are met: | ||
10 | .\" 1. Redistributions of source code must retain the above copyright | ||
11 | .\" notice, this list of conditions and the following disclaimer. | ||
12 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
13 | .\" notice, this list of conditions and the following disclaimer in the | ||
14 | .\" documentation and/or other materials provided with the distribution. | ||
15 | .\" 3. Neither the name of the project nor the names of its contributors | ||
16 | .\" may be used to endorse or promote products derived from this software | ||
17 | .\" without specific prior written permission. | ||
18 | .\" | ||
19 | .\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND | ||
20 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
21 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
22 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | ||
23 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
24 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
25 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
26 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
29 | .\" SUCH DAMAGE. | ||
30 | .\" | ||
31 | .Dd December 23, 2004 | ||
32 | .Dt INET6_OPTION_SPACE 3 | ||
33 | .Os | ||
34 | .\" | ||
35 | .Sh NAME | ||
36 | .Nm inet6_option_space , | ||
37 | .Nm inet6_option_init , | ||
38 | .Nm inet6_option_append , | ||
39 | .Nm inet6_option_alloc , | ||
40 | .Nm inet6_option_next , | ||
41 | .Nm inet6_option_find | ||
42 | .Nd IPv6 Hop-by-Hop and Destination Option Manipulation | ||
43 | .\" | ||
44 | .Sh LIBRARY | ||
45 | .Lb libc | ||
46 | .Sh SYNOPSIS | ||
47 | .In sys/types.h | ||
48 | .In netinet/in.h | ||
49 | .Ft "int" | ||
50 | .Fn inet6_option_space "int nbytes" | ||
51 | .Ft "int" | ||
52 | .Fn inet6_option_init "void *bp" "struct cmsghdr **cmsgp" "int type" | ||
53 | .Ft "int" | ||
54 | .Fn inet6_option_append "struct cmsghdr *cmsg" "const u_int8_t *typep" "int multx" "int plusy" | ||
55 | .Ft "u_int8_t *" | ||
56 | .Fn inet6_option_alloc "struct cmsghdr *cmsg" "int datalen" "int multx" "int plusy" | ||
57 | .Ft "int" | ||
58 | .Fn inet6_option_next "const struct cmsghdr *cmsg" "u_int8_t **tptrp" | ||
59 | .Ft "int" | ||
60 | .Fn inet6_option_find "const struct cmsghdr *cmsg" "u_int8_t **tptrp" "int type" | ||
61 | .\" | ||
62 | .Sh DESCRIPTION | ||
63 | .\" | ||
64 | Manipulating and parsing IPv6's Hop-by-Hop and Destination options is | ||
65 | complicated by the need to properly align and pad data as well as the | ||
66 | need to manipulate ancillary information that is not part of the data | ||
67 | stream. | ||
68 | RFC2292 defines a set of functions, which are implemented as | ||
69 | part of the Kame libraries, to support help developers create, change, | ||
70 | and parse Hop-by-Hope and Destination options. | ||
71 | All of the prototypes | ||
72 | for the option functions are defined in the | ||
73 | .In netinet/in.h | ||
74 | header file. | ||
75 | .\" | ||
76 | .Ss inet6_option_space | ||
77 | In order to determine the amount of space necessary to hold any option | ||
78 | the | ||
79 | .Fn inet6_option_space | ||
80 | function is called. | ||
81 | It returns the number of bytes required to hold | ||
82 | an option when it is stored as ancillary data, including the | ||
83 | .Li cmsghdr | ||
84 | structure at the beginning, and any necessary padding at the end. | ||
85 | The | ||
86 | .Li nbytes | ||
87 | argument indicates the size of the structure defining the option, | ||
88 | and must include any pad bytes at the beginning (the value | ||
89 | .Li y | ||
90 | in the alignment term | ||
91 | .Dq Li "xn + y" ) , | ||
92 | the type byte, the length byte, and the option data. | ||
93 | .Pp | ||
94 | Note: If multiple options are stored in a single ancillary data | ||
95 | object, which is the recommended technique, the | ||
96 | .Fn inet6_option_space | ||
97 | function overestimates the amount of space required by the size of | ||
98 | .Li N-1 | ||
99 | .Li cmsghdr | ||
100 | structures, where | ||
101 | .Li N | ||
102 | is the number of options to be stored in the object. | ||
103 | Usually this has | ||
104 | no impact because it is assumed that most Hop-by-Hop and Destination | ||
105 | option headers carry only one option as indicated in appendix B of RFC2460. | ||
106 | .\" | ||
107 | .Ss inet6_option_init | ||
108 | The | ||
109 | .Fn inet6_option_init | ||
110 | function is called to initialize any ancillary data object that will contain | ||
111 | a Hop-by-Hop or Destination option. | ||
112 | It returns | ||
113 | .Li 0 | ||
114 | on success and | ||
115 | .Li -1 | ||
116 | when an error occurs. | ||
117 | .Pp | ||
118 | The | ||
119 | .Fa bp | ||
120 | argument points to a previously allocated area of memory which must be | ||
121 | large enough to contain all the arguments that the application indents | ||
122 | to add later via | ||
123 | .Fn inet6_option_append | ||
124 | and | ||
125 | .Fn inet6_option_alloc | ||
126 | routines. | ||
127 | .Pp | ||
128 | The | ||
129 | .Fa cmsgp | ||
130 | argument is a pointer to a pointer to a | ||
131 | .Li cmsghdr | ||
132 | structure. | ||
133 | The | ||
134 | .Fa *cmsgp | ||
135 | argument | ||
136 | points to a | ||
137 | .Li cmsghdr | ||
138 | structure which is constructed by this function and stored in the | ||
139 | area of memory pointed to by | ||
140 | .Fa bp . | ||
141 | .Pp | ||
142 | The | ||
143 | .Fa type | ||
144 | is either | ||
145 | .Dv IPV6_HOPOPTS | ||
146 | or | ||
147 | .Dv IPV6_DSTOPTS | ||
148 | and is stored in the | ||
149 | .Li cmsg_type | ||
150 | member of the | ||
151 | .Li cmsghdr | ||
152 | structure mentioned above. | ||
153 | .\" | ||
154 | .Ss inet6_option_append | ||
155 | This function appends a Hop-by-Hop option or a Destination option into | ||
156 | an ancillary data object previously initialized by a call to | ||
157 | .Fn inet6_option_init . | ||
158 | The | ||
159 | .Fn inet6_option_append function returns | ||
160 | .Li 0 | ||
161 | if it succeeds or | ||
162 | .Li -1 | ||
163 | when an error occurs. | ||
164 | .Pp | ||
165 | The | ||
166 | .Fa cmsg | ||
167 | argument is a pointer to the | ||
168 | .Li cmsghdr | ||
169 | structure that was initialized by a call to | ||
170 | .Fn inet6_option_init . | ||
171 | .Pp | ||
172 | The | ||
173 | .Fa typep | ||
174 | argument is a pointer to the 8-bit option type. | ||
175 | All options are | ||
176 | encoded as type-length-value tuples and it is assumed that | ||
177 | the | ||
178 | .Fa typep | ||
179 | field is immediately followed by the 8-bit option data length field, | ||
180 | which is then followed by the option data. | ||
181 | .Pp | ||
182 | The option types of | ||
183 | .Li 0 | ||
184 | and | ||
185 | .Li 1 are reserved for the | ||
186 | .Li Pad1 | ||
187 | and | ||
188 | .Li PadN | ||
189 | options respectively. | ||
190 | All other values from | ||
191 | .Li 2 | ||
192 | through | ||
193 | .Li 255 | ||
194 | are available for applications to use. | ||
195 | .Pp | ||
196 | The option data length, since it is stored in 8 bites, must have a | ||
197 | value between | ||
198 | .Li 0 | ||
199 | and | ||
200 | .Li 255 , | ||
201 | inclusive. | ||
202 | .Pp | ||
203 | The | ||
204 | .Fa multx | ||
205 | argument | ||
206 | is the value | ||
207 | .Li x | ||
208 | in the alignment term | ||
209 | .Dq Li xn + y | ||
210 | and indicates the byte alignment necessary for the data. | ||
211 | Alignments may be specified as | ||
212 | .Li 1 , | ||
213 | .Li 2 , | ||
214 | .Li 4 , | ||
215 | or | ||
216 | .Li 8 | ||
217 | bytes, which is no alignment, 16 bit, 32 bit and 64 bit alignments | ||
218 | respectively. | ||
219 | .Pp | ||
220 | The | ||
221 | .Fa plusy | ||
222 | argument | ||
223 | is the value | ||
224 | .Li y | ||
225 | in the alignment term | ||
226 | .Dq Li xn + y | ||
227 | and must have a value between | ||
228 | .Li 0 | ||
229 | and | ||
230 | .Li 7 , | ||
231 | inclusive, indicating the amount of padding that is necessary for an | ||
232 | option. | ||
233 | .\" | ||
234 | .Ss inet6_option_alloc | ||
235 | The | ||
236 | .Fn inet6_option_alloc | ||
237 | function appends a Hop-by-Hop option or a Destination option into an | ||
238 | ancillary data object that has previously been initialized by a call to | ||
239 | .Fn inet6_option_init . | ||
240 | The | ||
241 | .Fn inet6_option_alloc | ||
242 | function returns a pointer to the 8-bit option type field that at the | ||
243 | beginning of the allocated the option on success, or | ||
244 | .Dv NULL | ||
245 | on an error. | ||
246 | .Pp | ||
247 | The difference between the | ||
248 | .Fn inet6_option_alloc | ||
249 | and | ||
250 | .Fn inet6_option_append | ||
251 | functions is that the latter copies the contents of a previously built | ||
252 | option into the ancillary data object while the former returns a | ||
253 | pointer to the place in the data object where the option's TLV must | ||
254 | then be built by the application. | ||
255 | .Pp | ||
256 | The | ||
257 | .Fa cmsg | ||
258 | argument is a pointer to a | ||
259 | .Li cmsghdr | ||
260 | structure that was initialized by | ||
261 | .Fn inet6_option_init . | ||
262 | .Pp | ||
263 | The | ||
264 | .Fa datalen | ||
265 | argument is the value of the option data length byte for this option. | ||
266 | This value is required as an argument to allow the function to | ||
267 | determine if padding must be appended at the end of the option. | ||
268 | (The | ||
269 | .Fn inet6_option_append | ||
270 | function does not need a data length argument | ||
271 | since the option data length must already be stored by the caller) | ||
272 | .Pp | ||
273 | The | ||
274 | .Fa multx | ||
275 | and | ||
276 | .Fa plusy | ||
277 | arguments | ||
278 | are identical to the arguments of the same name described in the | ||
279 | .Fn inet6_option_init | ||
280 | function above. | ||
281 | .\" | ||
282 | .Ss inet6_option_next | ||
283 | The | ||
284 | .Fn inet6_option_next | ||
285 | function is used to process Hop-by-Hop and Destination options that | ||
286 | are present in an ancillary data object. | ||
287 | When an option remains to | ||
288 | be processed, the return value of the | ||
289 | .Fn inet6_option_next | ||
290 | function is | ||
291 | .Li 0 | ||
292 | and the | ||
293 | .Fa *tptrp | ||
294 | argument points to the 8-bit option type field, which is followed by | ||
295 | the 8-bit option data length, and then the option data. | ||
296 | When no more | ||
297 | options remain to be processed, the return value is | ||
298 | .Li -1 | ||
299 | and | ||
300 | .Fa *tptrp | ||
301 | is | ||
302 | .Dv NULL | ||
303 | and when an error occurs, the return value is | ||
304 | .Li -1 | ||
305 | but the | ||
306 | .Fa *tptrp | ||
307 | argument is not | ||
308 | .Dv NULL . | ||
309 | This set of return values allows a program to easily loop through all | ||
310 | the options in an ancillary data object, checking for the error and | ||
311 | end of stream conditions along the way. | ||
312 | .Pp | ||
313 | When a valid option is returned the | ||
314 | .Fa cmsg | ||
315 | argument points to a | ||
316 | .Li cmsghdr | ||
317 | where the | ||
318 | .Li cmsg_level | ||
319 | equals | ||
320 | .Dv IPPROTO_IPV6 | ||
321 | and | ||
322 | .Li cmsg_type | ||
323 | is either | ||
324 | .Dv IPV6_HOPOPTS | ||
325 | or | ||
326 | .Dv IPV6_DSTOPTS . | ||
327 | .Pp | ||
328 | The | ||
329 | .Fa tptrp | ||
330 | argument is a pointer to a pointer to an 8-bit byte and | ||
331 | .Fa *tptrp | ||
332 | is used by the function to remember its place in the ancillary data | ||
333 | object each time the function is called. | ||
334 | When the | ||
335 | .Fn inet6_option_next | ||
336 | function is called for the first time on a given ancillary data object, | ||
337 | .Fa *tptrp | ||
338 | must be set to | ||
339 | .Dv NULL . | ||
340 | .Pp | ||
341 | Each time the function returns success, | ||
342 | the | ||
343 | .Fa *tptrp | ||
344 | argument points to the 8-bit option type field for the next option to | ||
345 | be processed. | ||
346 | .\" | ||
347 | .Ss inet6_option_find | ||
348 | The | ||
349 | .Fn inet6_option_find | ||
350 | function allows an application to search for a particular option type | ||
351 | in an ancillary data object. | ||
352 | The | ||
353 | .Fa cmsg | ||
354 | argument is a pointer to | ||
355 | .Li cmsghdr | ||
356 | structure in which the | ||
357 | .Li cmsg_level | ||
358 | element equals | ||
359 | .Dv IPPROTO_IPV6 | ||
360 | and the | ||
361 | .Li cmsg_type | ||
362 | element is either | ||
363 | .Dv IPV6_HOPOPTS | ||
364 | or | ||
365 | .Dv IPV6_DSTOPTS . | ||
366 | .Pp | ||
367 | The | ||
368 | .Fa tptrp | ||
369 | argument is handled exactly as in the | ||
370 | .Fn inet6_option_next | ||
371 | function described above. | ||
372 | .Pa | ||
373 | The | ||
374 | .fn inet6_option_find | ||
375 | function starts searching for an option of the specified type | ||
376 | beginning after the value of | ||
377 | .Fa *tptrp . | ||
378 | .\" | ||
379 | .Sh DIAGNOSTICS | ||
380 | The | ||
381 | .Fn inet6_option_init | ||
382 | and | ||
383 | .Fn inet6_option_append | ||
384 | functions return | ||
385 | .Li 0 | ||
386 | on success or | ||
387 | .Li -1 | ||
388 | on an error. | ||
389 | .Pp | ||
390 | The | ||
391 | .Fn inet6_option_alloc | ||
392 | function returns | ||
393 | .Dv NULL | ||
394 | on an error. | ||
395 | .Pp | ||
396 | When | ||
397 | .Fn inet6_option_next | ||
398 | or | ||
399 | .Fn inet6_option_find | ||
400 | detect an error they return | ||
401 | .Li -1 | ||
402 | setting | ||
403 | .Fa *tptrp | ||
404 | to non | ||
405 | .Dv NULL | ||
406 | value. | ||
407 | .\" | ||
408 | .Sh EXAMPLES | ||
409 | RFC2292 gives comprehensive examples in chapter 6. | ||
410 | .\" | ||
411 | .Sh SEE ALSO | ||
412 | .Rs | ||
413 | .%A W. Stevens | ||
414 | .%A M. Thomas | ||
415 | .%T "Advanced Sockets API for IPv6" | ||
416 | .%N RFC2292 | ||
417 | .%D February 1998 | ||
418 | .Re | ||
419 | .Rs | ||
420 | .%A S. Deering | ||
421 | .%A R. Hinden | ||
422 | .%T "Internet Protocol, Version 6 (IPv6) Specification" | ||
423 | .%N RFC2460 | ||
424 | .%D December 1998 | ||
425 | .Re | ||
426 | .\" | ||
427 | .Sh HISTORY | ||
428 | The implementation first appeared in KAME advanced networking kit. | ||
429 | .\" | ||
430 | .Sh STANDARDS | ||
431 | The functions are documented in | ||
432 | .Dq Advanced Sockets API for IPv6 | ||
433 | (RFC2292). | ||
434 | .\" | ||