summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/inet6_opt_init.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/inet6_opt_init.3')
-rw-r--r--src/lib/libc/net/inet6_opt_init.3336
1 files changed, 336 insertions, 0 deletions
diff --git a/src/lib/libc/net/inet6_opt_init.3 b/src/lib/libc/net/inet6_opt_init.3
new file mode 100644
index 0000000000..a97eb0f28b
--- /dev/null
+++ b/src/lib/libc/net/inet6_opt_init.3
@@ -0,0 +1,336 @@
1.\" $OpenBSD: inet6_opt_init.3,v 1.1 2006/12/09 01:12:28 itojun Exp $
2.\" $KAME: inet6_opt_init.3,v 1.7 2004/12/27 05:08:23 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_OPT_INIT 3
33.Os
34.\"
35.Sh NAME
36.Nm inet6_opt_init ,
37.Nm inet6_opt_append ,
38.Nm inet6_opt_finish ,
39.Nm inet6_opt_set_val ,
40.Nm inet6_opt_next ,
41.Nm inet6_opt_find ,
42.Nm inet6_opt_get_val
43.Nd IPv6 Hop-by-Hop and Destination Options manipulation
44.\"
45.Sh SYNOPSIS
46.In netinet/in.h
47.Ft "int"
48.Fn inet6_opt_init "void *extbuf" "socklen_t extlen"
49.Ft "int"
50.Fn inet6_opt_append "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t len" "u_int8_t align" "void **databufp"
51.Ft "int"
52.Fn inet6_opt_finish "void *extbuf" "socklen_t extlen" "int offset"
53.Ft "int"
54.Fn inet6_opt_set_val "void *databuf" "int offset" "void *val" "socklen_t vallen"
55.Ft "int"
56.Fn inet6_opt_next "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t *typep" "socklen_t *lenp" "void **databufp"
57.Ft "int"
58.Fn inet6_opt_find "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t *lenp" "void **databufp"
59.Ft "int"
60.Fn inet6_opt_get_val "void *databuf" "socklen_t offset" "void *val" "socklen_t vallen"
61.\"
62.Sh DESCRIPTION
63Building and parsing the Hop-by-Hop and Destination options is
64complicated.
65The advanced sockets API defines a set of functions to
66help applications create and manipulate Hop-by-Hope and Destination
67options.
68.\"This man page describes the functions specified in
69.\"IETF Draft RFC3542 while the
70.\".Xr inet6_options_space 3
71.\"man page documents the functions defined in RFC 2292.
72.\"It is expected
73.\"that this set of functions will supersede those in RFC 2292 but for
74.\"the time being both APIs are retained.
75These functions use the
76formatting rules specified in Appendix B in RFC2460, i.e., that the
77largest field is placed last in the option.
78The function prototypes
79for these functions are all contained in the header file
80.Aq netinet/in.h .
81.\"
82.Ss inet6_opt_init
83The
84.Fn inet6_opt_init
85function
86returns the number of bytes needed for an empty
87extension header, one without any options.
88If the
89.Va extbuf
90argument points to a valid section of memory
91then the
92.Fn inet6_opt_init
93function also initializes the extension header's length field.
94When attempting to initialize an extension buffer passed in the
95.Va extbuf argument
96.Fa extlen
97must be a positive multiple of 8 or else the function fails and
98returns \-1 to the caller.
99.\"
100.Ss inet6_opt_append
101The
102.Fn inet6_opt_append
103function can perform to different jobs.
104When a valid
105.Fa extbuf
106argument is supplied it appends an option to the extension buffer and
107returns the updated total length as well as a pointer to the newly
108created option in
109.Fa databufp .
110If the value
111of
112.Fa extbuf
113is
114.Dv NULL
115then the
116.Fn inet6_opt_append function only reports what the total length would
117be if the option were actually appended.
118The
119.Fa len
120and
121.Fa align
122arguments specify the length of the option and the required data
123alignment which must be used when appending the option.
124The
125.Fa offset
126argument should be the length returned by the
127.Fn inet6_opt_init
128function or a previous call to
129.Fn inet6_opt_append .
130.Pp
131The
132.Fa type
133argument is the 8-bit option type.
134.Pp
135After
136.Fn inet6_opt_append
137has been called, the application can use the buffer pointed to by
138.Fa databufp
139directly, or use
140.Fn inet6_opt_set_val
141to specify the data to be contained in the option.
142.Pp
143Option types of
144.Li 0
145and
146.Li 1
147are reserved for the
148.Li Pad1
149and
150.Li PadN
151options.
152All other values from 2 through 255 may be used by applications.
153.Pp
154The length of the option data is contained in an 8-bit value and so
155may contain any value from 0 through 255.
156.Pp
157The
158.Fa align
159parameter must have a value of 1, 2, 4, or 8 and cannot exceed the
160value of
161.Fa len .
162The alignment values represent no alignment, 16 bit, 32 bit and 64 bit
163alignments respectively.
164.\"
165.Ss inet6_opt_finish
166The
167.Fn inet6_opt_finish
168calculates the final padding necessary to make the extension header a
169multiple of 8 bytes, as required by the IPv6 extension header
170specification, and returns the extension header's updated total
171length.
172The
173.Fa offset
174argument should be the length returned by
175.Fn inet6_opt_init
176or
177.Fn inet6_opt_append .
178When
179.Fa extbuf
180is not
181.Dv NULL
182the function also sets up the appropriate padding bytes by inserting a
183Pad1 or PadN option of the proper length.
184.Pp
185If the extension header is too small to contain the proper padding
186then an error of \-1 is returned to the caller.
187.\"
188.Ss inet6_opt_set_val
189The
190.Fn inet6_opt_set_val
191function inserts data items of various sizes into the data portion of
192the option.
193The
194.Fa databuf
195argument is a pointer to memory that was returned by the
196.Fn inet6_opt_append
197call and the
198.Fa offset argument specifies where the option should be placed in the
199data buffer.
200The
201.Fa val
202argument points to an area of memory containing the data to be
203inserted into the extension header, and the
204.Fa vallen
205argument indicates how much data to copy.
206.Pp
207The caller should ensure that each field is aligned on its natural
208boundaries as described in Appendix B of RFC2460.
209.Pp
210The function returns the offset for the next field which is calculated as
211.Fa offset
212+
213.Fa vallen
214and is used when composing options with multiple fields.
215.\"
216.Ss inet6_opt_next
217The
218.Fn inet6_opt_next
219function parses received extension headers.
220The
221.Fa extbuf
222and
223.Fa extlen
224arguments specify the location and length of the extension header
225being parsed.
226The
227.Fa offset
228argument should either be zero, for the first option, or the length value
229returned by a previous call to
230.Fn inet6_opt_next
231or
232.Fn inet6_opt_find .
233The return value specifies the position where to continue scanning the
234extension buffer.
235The option is returned in the arguments
236.Fa typep , lenp ,
237and
238.Fa databufp .
239.Fa typep, lenp,
240and
241.Fa databufp
242point to the 8-bit option type, the 8-bit option length and the option
243data respectively.
244This function does not return any PAD1 or PADN options.
245When an error occurs or there are no more options the return
246value is \-1.
247.\"
248.Ss inet6_opt_find
249The
250.Fn inet6_opt_find
251function searches the extension buffer for a particular option type,
252passed in through the
253.Fa type
254argument.
255If the option is found then the
256.Fa lenp
257and
258.Fa databufp
259arguments are updated to point to the option's length and data
260respectively.
261.Fa extbuf
262and
263.Fa extlen
264must point to a valid extension buffer and give its length.
265The
266.Fa offset
267argument can be used to search from a location anywhere in the
268extension header.
269.Ss inet6_opt_get_val
270The
271.Fn inet6_opt_get_val
272function extracts data items of various sizes in the data portion of
273the option.
274The
275.Fa databuf
276is a pointer returned by the
277.Fn inet6_opt_next
278or
279.Fn inet6_opt_find
280functions.
281The
282.Fa val
283argument points where the data will be extracted.
284The
285.Fa offset
286argument specifies from where in the data portion of the option the
287value should be extracted; the first byte of option data is specified
288by an offset of zero.
289.Pp
290It is expected that each field is aligned on its natural boundaries as
291described in Appendix B of RFC2460.
292.Pp
293The function returns the offset for the next field
294by calculating
295.Fa offset
296+
297.Fa vallen
298which can be used when extracting option content with multiple fields.
299Robust receivers must verify alignment before calling this function.
300.\"
301.Sh DIAGNOSTICS
302All the functions return
303\-1
304on an error.
305.\"
306.Sh EXAMPLES
307RFC3542 gives comprehensive examples in Section 23.
308.Pp
309KAME also provides examples in the
310.Pa advapitest
311directory of its kit.
312.\"
313.Sh SEE ALSO
314.Rs
315.%A W. Stevens
316.%A M. Thomas
317.%A E. Nordmark
318.%A T. Jinmei
319.%T "Advanced Sockets API for IPv6"
320.%N RFC3542
321.%D October 2002
322.Re
323.Rs
324.%A S. Deering
325.%A R. Hinden
326.%T "Internet Protocol, Version 6 (IPv6) Specification"
327.%N RFC2460
328.%D December 1998
329.Re
330.Sh HISTORY
331The implementation first appeared in KAME advanced networking kit.
332.Sh STANDARDS
333The functions are documented in
334.Dq Advanced Sockets API for IPv6
335.Pq RFC3542 .
336.\"