diff options
Diffstat (limited to 'src/lib/libc/net/inet6_opt_init.3')
-rw-r--r-- | src/lib/libc/net/inet6_opt_init.3 | 336 |
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 | ||
63 | Building and parsing the Hop-by-Hop and Destination options is | ||
64 | complicated. | ||
65 | The advanced sockets API defines a set of functions to | ||
66 | help applications create and manipulate Hop-by-Hope and Destination | ||
67 | options. | ||
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. | ||
75 | These functions use the | ||
76 | formatting rules specified in Appendix B in RFC2460, i.e., that the | ||
77 | largest field is placed last in the option. | ||
78 | The function prototypes | ||
79 | for these functions are all contained in the header file | ||
80 | .Aq netinet/in.h . | ||
81 | .\" | ||
82 | .Ss inet6_opt_init | ||
83 | The | ||
84 | .Fn inet6_opt_init | ||
85 | function | ||
86 | returns the number of bytes needed for an empty | ||
87 | extension header, one without any options. | ||
88 | If the | ||
89 | .Va extbuf | ||
90 | argument points to a valid section of memory | ||
91 | then the | ||
92 | .Fn inet6_opt_init | ||
93 | function also initializes the extension header's length field. | ||
94 | When attempting to initialize an extension buffer passed in the | ||
95 | .Va extbuf argument | ||
96 | .Fa extlen | ||
97 | must be a positive multiple of 8 or else the function fails and | ||
98 | returns \-1 to the caller. | ||
99 | .\" | ||
100 | .Ss inet6_opt_append | ||
101 | The | ||
102 | .Fn inet6_opt_append | ||
103 | function can perform to different jobs. | ||
104 | When a valid | ||
105 | .Fa extbuf | ||
106 | argument is supplied it appends an option to the extension buffer and | ||
107 | returns the updated total length as well as a pointer to the newly | ||
108 | created option in | ||
109 | .Fa databufp . | ||
110 | If the value | ||
111 | of | ||
112 | .Fa extbuf | ||
113 | is | ||
114 | .Dv NULL | ||
115 | then the | ||
116 | .Fn inet6_opt_append function only reports what the total length would | ||
117 | be if the option were actually appended. | ||
118 | The | ||
119 | .Fa len | ||
120 | and | ||
121 | .Fa align | ||
122 | arguments specify the length of the option and the required data | ||
123 | alignment which must be used when appending the option. | ||
124 | The | ||
125 | .Fa offset | ||
126 | argument should be the length returned by the | ||
127 | .Fn inet6_opt_init | ||
128 | function or a previous call to | ||
129 | .Fn inet6_opt_append . | ||
130 | .Pp | ||
131 | The | ||
132 | .Fa type | ||
133 | argument is the 8-bit option type. | ||
134 | .Pp | ||
135 | After | ||
136 | .Fn inet6_opt_append | ||
137 | has been called, the application can use the buffer pointed to by | ||
138 | .Fa databufp | ||
139 | directly, or use | ||
140 | .Fn inet6_opt_set_val | ||
141 | to specify the data to be contained in the option. | ||
142 | .Pp | ||
143 | Option types of | ||
144 | .Li 0 | ||
145 | and | ||
146 | .Li 1 | ||
147 | are reserved for the | ||
148 | .Li Pad1 | ||
149 | and | ||
150 | .Li PadN | ||
151 | options. | ||
152 | All other values from 2 through 255 may be used by applications. | ||
153 | .Pp | ||
154 | The length of the option data is contained in an 8-bit value and so | ||
155 | may contain any value from 0 through 255. | ||
156 | .Pp | ||
157 | The | ||
158 | .Fa align | ||
159 | parameter must have a value of 1, 2, 4, or 8 and cannot exceed the | ||
160 | value of | ||
161 | .Fa len . | ||
162 | The alignment values represent no alignment, 16 bit, 32 bit and 64 bit | ||
163 | alignments respectively. | ||
164 | .\" | ||
165 | .Ss inet6_opt_finish | ||
166 | The | ||
167 | .Fn inet6_opt_finish | ||
168 | calculates the final padding necessary to make the extension header a | ||
169 | multiple of 8 bytes, as required by the IPv6 extension header | ||
170 | specification, and returns the extension header's updated total | ||
171 | length. | ||
172 | The | ||
173 | .Fa offset | ||
174 | argument should be the length returned by | ||
175 | .Fn inet6_opt_init | ||
176 | or | ||
177 | .Fn inet6_opt_append . | ||
178 | When | ||
179 | .Fa extbuf | ||
180 | is not | ||
181 | .Dv NULL | ||
182 | the function also sets up the appropriate padding bytes by inserting a | ||
183 | Pad1 or PadN option of the proper length. | ||
184 | .Pp | ||
185 | If the extension header is too small to contain the proper padding | ||
186 | then an error of \-1 is returned to the caller. | ||
187 | .\" | ||
188 | .Ss inet6_opt_set_val | ||
189 | The | ||
190 | .Fn inet6_opt_set_val | ||
191 | function inserts data items of various sizes into the data portion of | ||
192 | the option. | ||
193 | The | ||
194 | .Fa databuf | ||
195 | argument is a pointer to memory that was returned by the | ||
196 | .Fn inet6_opt_append | ||
197 | call and the | ||
198 | .Fa offset argument specifies where the option should be placed in the | ||
199 | data buffer. | ||
200 | The | ||
201 | .Fa val | ||
202 | argument points to an area of memory containing the data to be | ||
203 | inserted into the extension header, and the | ||
204 | .Fa vallen | ||
205 | argument indicates how much data to copy. | ||
206 | .Pp | ||
207 | The caller should ensure that each field is aligned on its natural | ||
208 | boundaries as described in Appendix B of RFC2460. | ||
209 | .Pp | ||
210 | The function returns the offset for the next field which is calculated as | ||
211 | .Fa offset | ||
212 | + | ||
213 | .Fa vallen | ||
214 | and is used when composing options with multiple fields. | ||
215 | .\" | ||
216 | .Ss inet6_opt_next | ||
217 | The | ||
218 | .Fn inet6_opt_next | ||
219 | function parses received extension headers. | ||
220 | The | ||
221 | .Fa extbuf | ||
222 | and | ||
223 | .Fa extlen | ||
224 | arguments specify the location and length of the extension header | ||
225 | being parsed. | ||
226 | The | ||
227 | .Fa offset | ||
228 | argument should either be zero, for the first option, or the length value | ||
229 | returned by a previous call to | ||
230 | .Fn inet6_opt_next | ||
231 | or | ||
232 | .Fn inet6_opt_find . | ||
233 | The return value specifies the position where to continue scanning the | ||
234 | extension buffer. | ||
235 | The option is returned in the arguments | ||
236 | .Fa typep , lenp , | ||
237 | and | ||
238 | .Fa databufp . | ||
239 | .Fa typep, lenp, | ||
240 | and | ||
241 | .Fa databufp | ||
242 | point to the 8-bit option type, the 8-bit option length and the option | ||
243 | data respectively. | ||
244 | This function does not return any PAD1 or PADN options. | ||
245 | When an error occurs or there are no more options the return | ||
246 | value is \-1. | ||
247 | .\" | ||
248 | .Ss inet6_opt_find | ||
249 | The | ||
250 | .Fn inet6_opt_find | ||
251 | function searches the extension buffer for a particular option type, | ||
252 | passed in through the | ||
253 | .Fa type | ||
254 | argument. | ||
255 | If the option is found then the | ||
256 | .Fa lenp | ||
257 | and | ||
258 | .Fa databufp | ||
259 | arguments are updated to point to the option's length and data | ||
260 | respectively. | ||
261 | .Fa extbuf | ||
262 | and | ||
263 | .Fa extlen | ||
264 | must point to a valid extension buffer and give its length. | ||
265 | The | ||
266 | .Fa offset | ||
267 | argument can be used to search from a location anywhere in the | ||
268 | extension header. | ||
269 | .Ss inet6_opt_get_val | ||
270 | The | ||
271 | .Fn inet6_opt_get_val | ||
272 | function extracts data items of various sizes in the data portion of | ||
273 | the option. | ||
274 | The | ||
275 | .Fa databuf | ||
276 | is a pointer returned by the | ||
277 | .Fn inet6_opt_next | ||
278 | or | ||
279 | .Fn inet6_opt_find | ||
280 | functions. | ||
281 | The | ||
282 | .Fa val | ||
283 | argument points where the data will be extracted. | ||
284 | The | ||
285 | .Fa offset | ||
286 | argument specifies from where in the data portion of the option the | ||
287 | value should be extracted; the first byte of option data is specified | ||
288 | by an offset of zero. | ||
289 | .Pp | ||
290 | It is expected that each field is aligned on its natural boundaries as | ||
291 | described in Appendix B of RFC2460. | ||
292 | .Pp | ||
293 | The function returns the offset for the next field | ||
294 | by calculating | ||
295 | .Fa offset | ||
296 | + | ||
297 | .Fa vallen | ||
298 | which can be used when extracting option content with multiple fields. | ||
299 | Robust receivers must verify alignment before calling this function. | ||
300 | .\" | ||
301 | .Sh DIAGNOSTICS | ||
302 | All the functions return | ||
303 | \-1 | ||
304 | on an error. | ||
305 | .\" | ||
306 | .Sh EXAMPLES | ||
307 | RFC3542 gives comprehensive examples in Section 23. | ||
308 | .Pp | ||
309 | KAME also provides examples in the | ||
310 | .Pa advapitest | ||
311 | directory 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 | ||
331 | The implementation first appeared in KAME advanced networking kit. | ||
332 | .Sh STANDARDS | ||
333 | The functions are documented in | ||
334 | .Dq Advanced Sockets API for IPv6 | ||
335 | .Pq RFC3542 . | ||
336 | .\" | ||