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