diff options
Diffstat (limited to 'src/lib/libc/net/inet6_option_space.3')
-rw-r--r-- | src/lib/libc/net/inet6_option_space.3 | 444 |
1 files changed, 444 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..4e5dc22711 --- /dev/null +++ b/src/lib/libc/net/inet6_option_space.3 | |||
@@ -0,0 +1,444 @@ | |||
1 | .\" $OpenBSD: inet6_option_space.3,v 1.13 2003/08/08 09:26:02 jmc Exp $ | ||
2 | .\" $KAME: inet6_option_space.3,v 1.7 2000/05/17 14:32:13 itojun Exp $ | ||
3 | .\" | ||
4 | .\" Copyright (c) 1983, 1987, 1991, 1993 | ||
5 | .\" The Regents of the University of California. 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 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. | ||
18 | .\" | ||
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 | ||
29 | .\" SUCH DAMAGE. | ||
30 | .\" | ||
31 | .Dd December 10, 1999 | ||
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 Options manipulation | ||
43 | .\" | ||
44 | .Sh SYNOPSIS | ||
45 | .Fd #include <netinet/in.h> | ||
46 | .Ft "int" | ||
47 | .Fn inet6_option_space "int nbytes" | ||
48 | .Ft "int" | ||
49 | .Fn inet6_option_init "void *bp" "struct cmsghdr **cmsgp" "int type" | ||
50 | .Ft "int" | ||
51 | .Fn inet6_option_append "struct cmsghdr *cmsg" "const u_int8_t *typep" "int multx" "int plusy" | ||
52 | .Ft "u_int8_t *" | ||
53 | .Fn inet6_option_alloc "struct cmsghdr *cmsg" "int datalen" "int multx" "int plusy" | ||
54 | .Ft "int" | ||
55 | .Fn inet6_option_next "const struct cmsghdr *cmsg" "u_int8_t **tptrp" | ||
56 | .Ft "int" | ||
57 | .Fn inet6_option_find "const struct cmsghdr *cmsg" "u_int8_t **tptrp" "int type" | ||
58 | .\" | ||
59 | .Sh DESCRIPTION | ||
60 | .\" | ||
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 | ||
67 | .Aq Pa netinet/in.h | ||
68 | header. | ||
69 | .\" | ||
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 | ||
74 | .Li cmsghdr | ||
75 | structure at the beginning, | ||
76 | and any padding at the end | ||
77 | .Po | ||
78 | to make its size a multiple of 8 bytes | ||
79 | .Pc . | ||
80 | The argument is the size of the structure defining the option, | ||
81 | which must include any pad bytes at the beginning | ||
82 | .Po | ||
83 | the value | ||
84 | .Li y | ||
85 | in the alignment term | ||
86 | .Dq Li xn + y | ||
87 | .Pc , | ||
88 | the type byte, the length byte, and the option data. | ||
89 | .Pp | ||
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 | ||
93 | .Li N-1 | ||
94 | .Li cmsghdr | ||
95 | structures, | ||
96 | where | ||
97 | .Li N | ||
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 | ||
101 | one option | ||
102 | .Pq appendix B of [RFC 2460] . | ||
103 | .\" | ||
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. | ||
108 | It returns | ||
109 | .Li 0 | ||
110 | on success or | ||
111 | .Li -1 | ||
112 | on an error. | ||
113 | .Pp | ||
114 | .Fa bp | ||
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 | ||
120 | and | ||
121 | .Fn inet6_option_alloc . | ||
122 | .Pp | ||
123 | .Fa cmsgp | ||
124 | is a pointer to a pointer to a | ||
125 | .Li cmsghdr | ||
126 | structure. | ||
127 | .Fa *cmsgp | ||
128 | is initialized by this function to point to the | ||
129 | .Li cmsghdr | ||
130 | structure constructed by this function in the buffer pointed to by | ||
131 | .Fa bp . | ||
132 | .Pp | ||
133 | .Fa type | ||
134 | is either | ||
135 | .Dv IPV6_HOPOPTS | ||
136 | or | ||
137 | .Dv IPV6_DSTOPTS . | ||
138 | This | ||
139 | .Fa type | ||
140 | is stored in the | ||
141 | .Li cmsg_type | ||
142 | member of the | ||
143 | .Li cmsghdr | ||
144 | structure pointed to by | ||
145 | .Fa *cmsgp . | ||
146 | .\" | ||
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 | ||
152 | .Li 0 | ||
153 | if it succeeds or | ||
154 | .Li -1 | ||
155 | on an error. | ||
156 | .Pp | ||
157 | .Fa cmsg | ||
158 | is a pointer to the | ||
159 | .Li cmsghdr | ||
160 | structure that must have been | ||
161 | initialized by | ||
162 | .Fn inet6_option_init . | ||
163 | .Pp | ||
164 | .Fa typep | ||
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. | ||
169 | The caller | ||
170 | initializes these three fields | ||
171 | .Pq the type-length-value, or TLV | ||
172 | before calling this function. | ||
173 | .Pp | ||
174 | The option type must have a value from | ||
175 | .Li 2 | ||
176 | to | ||
177 | .Li 255 , | ||
178 | inclusive. | ||
179 | .Po | ||
180 | .Li 0 | ||
181 | and | ||
182 | .Li 1 | ||
183 | are reserved for the | ||
184 | .Li Pad1 | ||
185 | and | ||
186 | .Li PadN | ||
187 | options, respectively. | ||
188 | .Pc | ||
189 | .Pp | ||
190 | The option data length must have a value between | ||
191 | .Li 0 | ||
192 | and | ||
193 | .Li 255 , | ||
194 | inclusive, and is the length of the option data that follows. | ||
195 | .Pp | ||
196 | .Fa multx | ||
197 | is the value | ||
198 | .Li x | ||
199 | in the alignment term | ||
200 | .Dq Li xn + y . | ||
201 | It must have a value of | ||
202 | .Li 1 , | ||
203 | .Li 2 , | ||
204 | .Li 4 , | ||
205 | or | ||
206 | .Li 8 . | ||
207 | .Pp | ||
208 | .Fa plusy | ||
209 | is the value | ||
210 | .Li y | ||
211 | in the alignment term | ||
212 | .Dq Li xn + y . | ||
213 | It must have a value between | ||
214 | .Li 0 | ||
215 | and | ||
216 | .Li 7 , | ||
217 | inclusive. | ||
218 | .\" | ||
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 | ||
225 | .Dv NULL | ||
226 | on an error. | ||
227 | .Pp | ||
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. | ||
234 | .Pp | ||
235 | .Fa cmsg | ||
236 | is a pointer to the | ||
237 | .Li cmsghdr | ||
238 | structure that must have been | ||
239 | initialized by | ||
240 | .Fn inet6_option_init . | ||
241 | .Pp | ||
242 | .Fa datalen | ||
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. | ||
246 | (The | ||
247 | .Fn inet6_option_append | ||
248 | function does not need a data length argument | ||
249 | since the option data length must already be stored by the caller.) | ||
250 | .Pp | ||
251 | .Fa multx | ||
252 | is the value | ||
253 | .Li x | ||
254 | in the alignment term | ||
255 | .Dq Li xn + y . | ||
256 | It must have a value of | ||
257 | .Li 1 , | ||
258 | .Li 2 , | ||
259 | .Li 4 , | ||
260 | or | ||
261 | .Li 8 . | ||
262 | .Pp | ||
263 | .Fa plusy | ||
264 | is the value | ||
265 | .Li y | ||
266 | in the alignment term | ||
267 | .Dq Li xn + y . | ||
268 | It must have a value between | ||
269 | .Li 0 | ||
270 | and | ||
271 | .Li 7 , | ||
272 | inclusive. | ||
273 | .\" | ||
274 | .Ss inet6_option_next | ||
275 | This function processes the next Hop-by-Hop option or Destination | ||
276 | option in an ancillary data object. | ||
277 | If another option remains to be | ||
278 | processed, the return value of the function is | ||
279 | .Li 0 | ||
280 | and | ||
281 | .Fa *tptrp | ||
282 | points to | ||
283 | the 8-bit option type field | ||
284 | (which is followed by the 8-bit option | ||
285 | data length, followed by the option data). | ||
286 | If no more options remain | ||
287 | to be processed, the return value is | ||
288 | .Li -1 | ||
289 | and | ||
290 | .Fa *tptrp | ||
291 | is | ||
292 | .Dv NULL . | ||
293 | If an error occurs, the return value is | ||
294 | .Li -1 | ||
295 | and | ||
296 | .Fa *tptrp | ||
297 | is not | ||
298 | .Dv NULL . | ||
299 | .Pp | ||
300 | .Fa cmsg | ||
301 | is a pointer to | ||
302 | .Li cmsghdr | ||
303 | structure of which | ||
304 | .Li cmsg_level | ||
305 | equals | ||
306 | .Dv IPPROTO_IPV6 | ||
307 | and | ||
308 | .Li cmsg_type | ||
309 | equals either | ||
310 | .Dv IPV6_HOPOPTS | ||
311 | or | ||
312 | .Dv IPV6_DSTOPTS . | ||
313 | .Pp | ||
314 | .Fa tptrp | ||
315 | is a pointer to a pointer to an 8-bit byte and | ||
316 | .Fa *tptrp | ||
317 | is used | ||
318 | by the function to remember its place in the ancillary data object | ||
319 | each time the function is called. | ||
320 | The first time this function is | ||
321 | called for a given ancillary data object, | ||
322 | .Fa *tptrp | ||
323 | must be set to | ||
324 | .Dv NULL . | ||
325 | .Pp | ||
326 | Each time this function returns success, | ||
327 | .Fa *tptrp | ||
328 | points to the 8-bit | ||
329 | option type field for the next option to be processed. | ||
330 | .\" | ||
331 | .Ss inet6_option_find | ||
332 | This function is similar to the previously described | ||
333 | .Fn inet6_option_next | ||
334 | function, except this function lets the caller | ||
335 | specify the option type to be searched for, instead of always | ||
336 | returning the next option in the ancillary data object. | ||
337 | .Fa cmsg | ||
338 | is a | ||
339 | pointer to | ||
340 | .Li cmsghdr | ||
341 | structure of which | ||
342 | .Li cmsg_level | ||
343 | equals | ||
344 | .Dv IPPROTO_IPV6 | ||
345 | and | ||
346 | .Li cmsg_type | ||
347 | equals either | ||
348 | .Dv IPV6_HOPOPTS | ||
349 | or | ||
350 | .Dv IPV6_DSTOPTS . | ||
351 | .Pp | ||
352 | .Fa tptrp | ||
353 | is a pointer to a pointer to an 8-bit byte and | ||
354 | .Fa *tptrp | ||
355 | is used | ||
356 | by the function to remember its place in the ancillary data object | ||
357 | each time the function is called. | ||
358 | The first time this function is | ||
359 | called for a given ancillary data object, | ||
360 | .Fa *tptrp | ||
361 | must be set to | ||
362 | .Dv NULL . | ||
363 | .Pp | ||
364 | This function starts searching for an option of the specified type | ||
365 | beginning after the value of | ||
366 | .Fa *tptrp . | ||
367 | If an option of the specified | ||
368 | type is located, this function returns | ||
369 | .Li 0 | ||
370 | and | ||
371 | .Fa *tptrp | ||
372 | points to the 8- | ||
373 | bit option type field for the option of the specified type. | ||
374 | If an | ||
375 | option of the specified type is not located, the return value is | ||
376 | .Li -1 | ||
377 | and | ||
378 | .Fa *tptrp | ||
379 | is | ||
380 | .Dv NULL . | ||
381 | If an error occurs, the return value is | ||
382 | .Li -1 | ||
383 | and | ||
384 | .Fa *tptrp | ||
385 | is not | ||
386 | .Dv NULL . | ||
387 | .\" | ||
388 | .Sh EXAMPLES | ||
389 | RFC 2292 gives comprehensive examples in chapter 6. | ||
390 | .\" | ||
391 | .Sh DIAGNOSTICS | ||
392 | .Fn inet6_option_init | ||
393 | and | ||
394 | .Fn inet6_option_append | ||
395 | return | ||
396 | .Li 0 | ||
397 | on success or | ||
398 | .Li -1 | ||
399 | on an error. | ||
400 | .Pp | ||
401 | .Fn inet6_option_alloc | ||
402 | returns | ||
403 | .Dv NULL | ||
404 | on an error. | ||
405 | .Pp | ||
406 | On errors, | ||
407 | .Fn inet6_option_next | ||
408 | and | ||
409 | .Fn inet6_option_find | ||
410 | return | ||
411 | .Li -1 | ||
412 | setting | ||
413 | .Fa *tptrp | ||
414 | to non | ||
415 | .Dv NULL | ||
416 | value. | ||
417 | .\" | ||
418 | .Sh SEE ALSO | ||
419 | .Rs | ||
420 | .%A W. Stevens | ||
421 | .%A M. Thomas | ||
422 | .%T "Advanced Sockets API for IPv6" | ||
423 | .%N RFC 2292 | ||
424 | .%D February 1998 | ||
425 | .Re | ||
426 | .Rs | ||
427 | .%A S. Deering | ||
428 | .%A R. Hinden | ||
429 | .%T "Internet Protocol, Version 6 (IPv6) Specification" | ||
430 | .%N RFC 2460 | ||
431 | .%D December 1998 | ||
432 | .Re | ||
433 | .\" | ||
434 | .Sh STANDARDS | ||
435 | The functions | ||
436 | are documented in | ||
437 | .Dq Advanced Sockets API for IPv6 | ||
438 | .Pq RFC 2292 . | ||
439 | .\" | ||
440 | .Sh HISTORY | ||
441 | The implementation first appeared in KAME advanced networking kit. | ||
442 | .\" | ||
443 | .Sh BUGS | ||
444 | The text was shamelessly copied from RFC 2292. | ||