1 .\" $NetBSD: inet6_option_space.3,v 1.15 2004/12/20 18:30:26 christos Exp $
2 .\" $KAME: inet6_option_space.3,v 1.7 2000/05/17 14:32:13 itojun Exp $
4 .\" Copyright (c) 1983, 1987, 1991, 1993
5 .\" The Regents of the University of California. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
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 University 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.
19 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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
32 .Dt INET6_OPTION_SPACE 3
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 ,
42 .Nd IPv6 Hop-by-Hop and Destination Options manipulation
47 .Fn inet6_option_space "int nbytes"
49 .Fn inet6_option_init "void *bp" "struct cmsghdr **cmsgp" "int type"
51 .Fn inet6_option_append "struct cmsghdr *cmsg" "const uint8_t *typep" "int multx" "int plusy"
53 .Fn inet6_option_alloc "struct cmsghdr *cmsg" "int datalen" "int multx" "int plusy"
55 .Fn inet6_option_next "const struct cmsghdr *cmsg" "uint8_t **tptrp"
57 .Fn inet6_option_find "const struct cmsghdr *cmsg" "uint8_t **tptrp" "int type"
61 Building and parsing the Hop-by-Hop and Destination options is
62 complicated due to alignment constraints, padding and
63 ancillary data manipulation.
64 RFC 2292 defines a set of functions to help the application.
65 The function prototypes for
66 these functions are all in the
70 .Ss inet6_option_space
71 .Fn inet6_option_space
72 returns the number of bytes required to hold an option when it is stored as
73 ancillary data, including the
75 structure at the beginning,
76 and any padding at the end
78 to make its size a multiple of 8 bytes
80 The argument is the size of the structure defining the option,
81 which must include any pad bytes at the beginning
88 the type byte, the length byte, and the option data.
90 Note: If multiple options are stored in a single ancillary data
91 object, which is the recommended technique, this function
92 overestimates the amount of space required by the size of
98 is the number of options to be stored in the object.
99 This is of little consequence, since it is assumed that most
100 Hop-by-Hop option headers and Destination option headers carry only
102 .Pq appendix B of [RFC 2460] .
104 .Ss inet6_option_init
105 .Fn inet6_option_init
106 is called once per ancillary data object that will
107 contain either Hop-by-Hop or Destination options.
115 is a pointer to previously allocated space that will contain the
116 ancillary data object.
117 It must be large enough to contain all the
118 individual options to be added by later calls to
119 .Fn inet6_option_append
121 .Fn inet6_option_alloc .
124 is a pointer to a pointer to a
128 is initialized by this function to point to the
130 structure constructed by this function in the buffer pointed to by
144 structure pointed to by
147 .Ss inet6_option_append
148 This function appends a Hop-by-Hop option or a Destination option
149 into an ancillary data object that has been initialized by
150 .Fn inet6_option_init .
151 This function returns
160 structure that must have been
162 .Fn inet6_option_init .
165 is a pointer to the 8-bit option type.
166 It is assumed that this
167 field is immediately followed by the 8-bit option data length field,
168 which is then followed immediately by the option data.
170 initializes these three fields
171 .Pq the type-length-value, or TLV
172 before calling this function.
174 The option type must have a value from
187 options, respectively.
190 The option data length must have a value between
194 inclusive, and is the length of the option data that follows.
199 in the alignment term
201 It must have a value of
211 in the alignment term
213 It must have a value between
219 .Ss inet6_option_alloc
220 This function appends a Hop-by-Hop option or a Destination option
221 into an ancillary data object that has been initialized by
222 .Fn inet6_option_init .
223 This function returns a pointer to the 8-bit
224 option type field that starts the option on success, or
228 The difference between this function and
229 .Fn inet6_option_append
230 is that the latter copies the contents of a previously built option into
231 the ancillary data object while the current function returns a
232 pointer to the space in the data object where the option's TLV must
233 then be built by the caller.
238 structure that must have been
240 .Fn inet6_option_init .
243 is the value of the option data length byte for this option.
244 This value is required as an argument to allow the function to
245 determine if padding must be appended at the end of the option.
248 .Fn inet6_option_append
249 function does not need a data length argument
250 since the option data length must already be stored by the caller.
256 in the alignment term
258 It must have a value of
268 in the alignment term
270 It must have a value between
276 .Ss inet6_option_next
277 This function processes the next Hop-by-Hop option or Destination
278 option in an ancillary data object.
279 If another option remains to be
280 processed, the return value of the function is
285 the 8-bit option type field
287 which is followed by the 8-bit option
288 data length, followed by the option data
290 If no more options remain
291 to be processed, the return value is
297 If an error occurs, the return value is
319 is a pointer to a pointer to an 8-bit byte and
322 by the function to remember its place in the ancillary data object
323 each time the function is called.
324 The first time this function is
325 called for a given ancillary data object,
330 Each time this function returns success,
333 option type field for the next option to be processed.
335 .Ss inet6_option_find
336 This function is similar to the previously described
337 .Fn inet6_option_next
338 function, except this function lets the caller
339 specify the option type to be searched for, instead of always
340 returning the next option in the ancillary data object.
357 is a pointer to a pointer to an 8-bit byte and
360 by the function to remember its place in the ancillary data object
361 each time the function is called.
362 The first time this function is
363 called for a given ancillary data object,
368 This function starts searching for an option of the specified type
369 beginning after the value of
371 If an option of the specified
372 type is located, this function returns
377 bit option type field for the option of the specified type.
379 option of the specified type is not located, the return value is
385 If an error occurs, the return value is
393 RFC 2292 gives comprehensive examples in chapter 6.
396 .Fn inet6_option_init
398 .Fn inet6_option_append
405 .Fn inet6_option_alloc
411 .Fn inet6_option_next
413 .Fn inet6_option_find
426 .%T "Advanced Sockets API for IPv6"
433 .%T "Internet Protocol, Version 6 (IPv6) Specification"
441 .Dq Advanced Sockets API for IPv6
445 The implementation first appeared in KAME advanced networking kit.
448 The text was shamelessly copied from RFC 2292.