summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/inet6_option_space.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/inet6_option_space.3')
-rw-r--r--src/lib/libc/net/inet6_option_space.3434
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.\"
64Manipulating and parsing IPv6's Hop-by-Hop and Destination options is
65complicated by the need to properly align and pad data as well as the
66need to manipulate ancillary information that is not part of the data
67stream.
68RFC2292 defines a set of functions, which are implemented as
69part of the Kame libraries, to support help developers create, change,
70and parse Hop-by-Hope and Destination options.
71All of the prototypes
72for the option functions are defined in the
73.In netinet/in.h
74header file.
75.\"
76.Ss inet6_option_space
77In order to determine the amount of space necessary to hold any option
78the
79.Fn inet6_option_space
80function is called.
81It returns the number of bytes required to hold
82an option when it is stored as ancillary data, including the
83.Li cmsghdr
84structure at the beginning, and any necessary padding at the end.
85The
86.Li nbytes
87argument indicates the size of the structure defining the option,
88and must include any pad bytes at the beginning (the value
89.Li y
90in the alignment term
91.Dq Li "xn + y" ) ,
92the type byte, the length byte, and the option data.
93.Pp
94Note: If multiple options are stored in a single ancillary data
95object, which is the recommended technique, the
96.Fn inet6_option_space
97function overestimates the amount of space required by the size of
98.Li N-1
99.Li cmsghdr
100structures, where
101.Li N
102is the number of options to be stored in the object.
103Usually this has
104no impact because it is assumed that most Hop-by-Hop and Destination
105option headers carry only one option as indicated in appendix B of RFC2460.
106.\"
107.Ss inet6_option_init
108The
109.Fn inet6_option_init
110function is called to initialize any ancillary data object that will contain
111a Hop-by-Hop or Destination option.
112It returns
113.Li 0
114on success and
115.Li -1
116when an error occurs.
117.Pp
118The
119.Fa bp
120argument points to a previously allocated area of memory which must be
121large enough to contain all the arguments that the application indents
122to add later via
123.Fn inet6_option_append
124and
125.Fn inet6_option_alloc
126routines.
127.Pp
128The
129.Fa cmsgp
130argument is a pointer to a pointer to a
131.Li cmsghdr
132structure.
133The
134.Fa *cmsgp
135argument
136points to a
137.Li cmsghdr
138structure which is constructed by this function and stored in the
139area of memory pointed to by
140.Fa bp .
141.Pp
142The
143.Fa type
144is either
145.Dv IPV6_HOPOPTS
146or
147.Dv IPV6_DSTOPTS
148and is stored in the
149.Li cmsg_type
150member of the
151.Li cmsghdr
152structure mentioned above.
153.\"
154.Ss inet6_option_append
155This function appends a Hop-by-Hop option or a Destination option into
156an ancillary data object previously initialized by a call to
157.Fn inet6_option_init .
158The
159.Fn inet6_option_append function returns
160.Li 0
161if it succeeds or
162.Li -1
163when an error occurs.
164.Pp
165The
166.Fa cmsg
167argument is a pointer to the
168.Li cmsghdr
169structure that was initialized by a call to
170.Fn inet6_option_init .
171.Pp
172The
173.Fa typep
174argument is a pointer to the 8-bit option type.
175All options are
176encoded as type-length-value tuples and it is assumed that
177the
178.Fa typep
179field is immediately followed by the 8-bit option data length field,
180which is then followed by the option data.
181.Pp
182The option types of
183.Li 0
184and
185.Li 1 are reserved for the
186.Li Pad1
187and
188.Li PadN
189options respectively.
190All other values from
191.Li 2
192through
193.Li 255
194are available for applications to use.
195.Pp
196The option data length, since it is stored in 8 bites, must have a
197value between
198.Li 0
199and
200.Li 255 ,
201inclusive.
202.Pp
203The
204.Fa multx
205argument
206is the value
207.Li x
208in the alignment term
209.Dq Li xn + y
210and indicates the byte alignment necessary for the data.
211Alignments may be specified as
212.Li 1 ,
213.Li 2 ,
214.Li 4 ,
215or
216.Li 8
217bytes, which is no alignment, 16 bit, 32 bit and 64 bit alignments
218respectively.
219.Pp
220The
221.Fa plusy
222argument
223is the value
224.Li y
225in the alignment term
226.Dq Li xn + y
227and must have a value between
228.Li 0
229and
230.Li 7 ,
231inclusive, indicating the amount of padding that is necessary for an
232option.
233.\"
234.Ss inet6_option_alloc
235The
236.Fn inet6_option_alloc
237function appends a Hop-by-Hop option or a Destination option into an
238ancillary data object that has previously been initialized by a call to
239.Fn inet6_option_init .
240The
241.Fn inet6_option_alloc
242function returns a pointer to the 8-bit option type field that at the
243beginning of the allocated the option on success, or
244.Dv NULL
245on an error.
246.Pp
247The difference between the
248.Fn inet6_option_alloc
249and
250.Fn inet6_option_append
251functions is that the latter copies the contents of a previously built
252option into the ancillary data object while the former returns a
253pointer to the place in the data object where the option's TLV must
254then be built by the application.
255.Pp
256The
257.Fa cmsg
258argument is a pointer to a
259.Li cmsghdr
260structure that was initialized by
261.Fn inet6_option_init .
262.Pp
263The
264.Fa datalen
265argument is the value of the option data length byte for this option.
266This value is required as an argument to allow the function to
267determine if padding must be appended at the end of the option.
268(The
269.Fn inet6_option_append
270function does not need a data length argument
271since the option data length must already be stored by the caller)
272.Pp
273The
274.Fa multx
275and
276.Fa plusy
277arguments
278are identical to the arguments of the same name described in the
279.Fn inet6_option_init
280function above.
281.\"
282.Ss inet6_option_next
283The
284.Fn inet6_option_next
285function is used to process Hop-by-Hop and Destination options that
286are present in an ancillary data object.
287When an option remains to
288be processed, the return value of the
289.Fn inet6_option_next
290function is
291.Li 0
292and the
293.Fa *tptrp
294argument points to the 8-bit option type field, which is followed by
295the 8-bit option data length, and then the option data.
296When no more
297options remain to be processed, the return value is
298.Li -1
299and
300.Fa *tptrp
301is
302.Dv NULL
303and when an error occurs, the return value is
304.Li -1
305but the
306.Fa *tptrp
307argument is not
308.Dv NULL .
309This set of return values allows a program to easily loop through all
310the options in an ancillary data object, checking for the error and
311end of stream conditions along the way.
312.Pp
313When a valid option is returned the
314.Fa cmsg
315argument points to a
316.Li cmsghdr
317where the
318.Li cmsg_level
319equals
320.Dv IPPROTO_IPV6
321and
322.Li cmsg_type
323is either
324.Dv IPV6_HOPOPTS
325or
326.Dv IPV6_DSTOPTS .
327.Pp
328The
329.Fa tptrp
330argument is a pointer to a pointer to an 8-bit byte and
331.Fa *tptrp
332is used by the function to remember its place in the ancillary data
333object each time the function is called.
334When the
335.Fn inet6_option_next
336function is called for the first time on a given ancillary data object,
337.Fa *tptrp
338must be set to
339.Dv NULL .
340.Pp
341Each time the function returns success,
342the
343.Fa *tptrp
344argument points to the 8-bit option type field for the next option to
345be processed.
346.\"
347.Ss inet6_option_find
348The
349.Fn inet6_option_find
350function allows an application to search for a particular option type
351in an ancillary data object.
352The
353.Fa cmsg
354argument is a pointer to
355.Li cmsghdr
356structure in which the
357.Li cmsg_level
358element equals
359.Dv IPPROTO_IPV6
360and the
361.Li cmsg_type
362element is either
363.Dv IPV6_HOPOPTS
364or
365.Dv IPV6_DSTOPTS .
366.Pp
367The
368.Fa tptrp
369argument is handled exactly as in the
370.Fn inet6_option_next
371function described above.
372.Pa
373The
374.fn inet6_option_find
375function starts searching for an option of the specified type
376beginning after the value of
377.Fa *tptrp .
378.\"
379.Sh DIAGNOSTICS
380The
381.Fn inet6_option_init
382and
383.Fn inet6_option_append
384functions return
385.Li 0
386on success or
387.Li -1
388on an error.
389.Pp
390The
391.Fn inet6_option_alloc
392function returns
393.Dv NULL
394on an error.
395.Pp
396When
397.Fn inet6_option_next
398or
399.Fn inet6_option_find
400detect an error they return
401.Li -1
402setting
403.Fa *tptrp
404to non
405.Dv NULL
406value.
407.\"
408.Sh EXAMPLES
409RFC2292 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
428The implementation first appeared in KAME advanced networking kit.
429.\"
430.Sh STANDARDS
431The functions are documented in
432.Dq Advanced Sockets API for IPv6
433(RFC2292).
434.\"