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.3452
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.\"
67Building and parsing the Hop-by-Hop and Destination options is
68complicated due to alignment constranints, padding and
69ancillary data manipulation.
70RFC2292 defines a set of functions to help the application.
71The function prototypes for
72these functions are all in the
73.Aq Li netinet/in.h
74header.
75.\"
76.Ss inet6_option_space
77.Fn inet6_option_space
78returns the number of bytes required to hold an option when it is stored as
79ancillary data, including the
80.Li cmsghdr
81structure at the beginning,
82and any padding at the end
83.Po
84to make its size a multiple of 8 bytes
85.Pc .
86The argument is the size of the structure defining the option,
87which must include any pad bytes at the beginning
88.Po
89the value
90.Li y
91in the alignment term
92.Dq Li xn + y
93.Pc ,
94the type byte, the length byte, and the option data.
95.Pp
96Note: If multiple options are stored in a single ancillary data
97object, which is the recommended technique, this function
98overestimates the amount of space required by the size of
99.Li N-1
100.Li cmsghdr
101structures,
102where
103.Li N
104is the number of options to be stored in the object.
105This is of little consequence, since it is assumed that most
106Hop-by-Hop option headers and Destination option headers carry only
107one option
108.Pq appendix B of [RFC-2460] .
109.\"
110.Ss inet6_option_init
111.Fn inet6_option_init
112is called once per ancillary data object that will
113contain either Hop-by-Hop or Destination options.
114It returns
115.Li 0
116on success or
117.Li -1
118on an error.
119.Pp
120.Fa bp
121is a pointer to previously allocated space that will contain the
122ancillary data object.
123It must be large enough to contain all the
124individual options to be added by later calls to
125.Fn inet6_option_append
126and
127.Fn inet6_option_alloc .
128.Pp
129.Fa cmsgp
130is a pointer to a pointer to a
131.Li cmsghdr
132structure.
133.Fa *cmsgp
134is initialized by this function to point to the
135.Li cmsghdr
136structure constructed by this function in the buffer pointed to by
137.Fa bp .
138.Pp
139.Fa type
140is either
141.Dv IPV6_HOPOPTS
142or
143.Dv IPV6_DSTOPTS .
144This
145.Fa type
146is stored in the
147.Li cmsg_type
148member of the
149.Li cmsghdr
150structure pointed to by
151.Fa *cmsgp .
152.\"
153.Ss inet6_option_append
154This function appends a Hop-by-Hop option or a Destination option
155into an ancillary data object that has been initialized by
156.Fn inet6_option_init .
157This function returns
158.Li 0
159if it succeeds or
160.Li -1
161on an error.
162.Pp
163.Fa cmsg
164is a pointer to the
165.Li cmsghdr
166structure that must have been
167initialized by
168.Fn inet6_option_init .
169.Pp
170.Fa typep
171is a pointer to the 8-bit option type.
172It is assumed that this
173field is immediately followed by the 8-bit option data length field,
174which is then followed immediately by the option data.
175The caller
176initializes these three fields
177.Pq the type-length-value, or TLV
178before calling this function.
179.Pp
180The option type must have a value from
181.Li 2
182to
183.Li 255 , inclusive.
184.Po
185.Li 0
186and
187.Li 1
188are reserved for the
189.Li Pad1
190and
191.Li PadN
192options, respectively.
193.Pc
194.Pp
195The option data length must have a value between
196.Li 0
197and
198.Li 255 ,
199inclusive, and is the length of the option data that follows.
200.Pp
201.Fa multx
202is the value
203.Li x
204in the alignment term
205.Dq Li xn + y .
206It must have a value of
207.Li 1 ,
208.Li 2 ,
209.Li 4 ,
210or
211.Li 8 .
212.Pp
213.Fa plusy
214is the value
215.Li y
216in the alignment term
217.Dq Li xn + y .
218It must have a value between
219.Li 0
220and
221.Li 7 ,
222inclusive.
223.\"
224.Ss inet6_option_alloc
225This function appends a Hop-by-Hop option or a Destination option
226into an ancillary data object that has been initialized by
227.Fn inet6_option_init .
228This function returns a pointer to the 8-bit
229option type field that starts the option on success, or
230.Dv NULL
231on an error.
232.Pp
233The difference between this function and
234.Fn inet6_option_append
235is that the latter copies the contents of a previously built option into
236the ancillary data object while the current function returns a
237pointer to the space in the data object where the option's TLV must
238then be built by the caller.
239.Pp
240.Fa cmsg
241is a pointer to the
242.Li cmsghdr
243structure that must have been
244initialized by
245.Fn inet6_option_init .
246.Pp
247.Fa datalen
248is the value of the option data length byte for this option.
249This value is required as an argument to allow the function to
250determine if padding must be appended at the end of the option.
251.Po
252The
253.Fn inet6_option_append
254function does not need a data length argument
255since the option data length must already be stored by the caller.
256.Pc
257.Pp
258.Fa multx
259is the value
260.Li x
261in the alignment term
262.Dq Li xn + y .
263It must have a value of
264.Li 1 ,
265.Li 2 ,
266.Li 4 ,
267or
268.Li 8 .
269.Pp
270.Fa plusy
271is the value
272.Li y
273in the alignment term
274.Dq Li xn + y .
275It must have a value between
276.Li 0
277and
278.Li 7 ,
279inclusive.
280.\"
281.Ss inet6_option_next
282This function processes the next Hop-by-Hop option or Destination
283option in an ancillary data object.
284If another option remains to be
285processed, the return value of the function is
286.Li 0
287and
288.Fa *tptrp
289points to
290the 8-bit option type field
291.Po
292which is followed by the 8-bit option
293data length, followed by the option data
294.Pc .
295If no more options remain
296to be processed, the return value is
297.Li -1
298and
299.Fa *tptrp
300is
301.Dv NULL .
302If an error occurs, the return value is
303.Li -1
304and
305.Fa *tptrp
306is not
307.Dv NULL .
308.Pp
309.Fa cmsg
310is a pointer to
311.Li cmsghdr
312structure of which
313.Li cmsg_level
314equals
315.Dv IPPROTO_IPV6
316and
317.Li cmsg_type
318equals either
319.Dv IPV6_HOPOPTS
320or
321.Dv IPV6_DSTOPTS .
322.Pp
323.Fa tptrp
324is a pointer to a pointer to an 8-bit byte and
325.Fa *tptrp
326is used
327by the function to remember its place in the ancillary data object
328each time the function is called.
329The first time this function is
330called for a given ancillary data object,
331.Fa *tptrp
332must be set to
333.Dv NULL .
334.Pp
335Each time this function returns success,
336.Fa *tptrp
337points to the 8-bit
338option type field for the next option to be processed.
339.\"
340.Ss inet6_option_find
341This function is similar to the previously described
342.Fn inet6_option_next
343function, except this function lets the caller
344specify the option type to be searched for, instead of always
345returning the next option in the ancillary data object.
346.Fa cmsg
347is a
348pointer to
349.Li cmsghdr
350structure of which
351.Li cmsg_level
352equals
353.Dv IPPROTO_IPV6
354and
355.Li cmsg_type
356equals either
357.Dv IPV6_HOPOPTS
358or
359.Dv IPV6_DSTOPTS .
360.Pp
361.Fa tptrp
362is a pointer to a pointer to an 8-bit byte and
363.Fa *tptrp
364is used
365by the function to remember its place in the ancillary data object
366each time the function is called.
367The first time this function is
368called for a given ancillary data object,
369.Fa *tptrp
370must be set to
371.Dv NULL .
372.Pa
373This function starts searching for an option of the specified type
374beginning after the value of
375.Fa *tptrp .
376If an option of the specified
377type is located, this function returns
378.Li 0
379and
380.Fa *tptrp
381points to the 8-
382bit option type field for the option of the specified type.
383If an
384option of the specified type is not located, the return value is
385.Li -1
386and
387.Fa *tptrp
388is
389.Dv NULL .
390If an error occurs, the return value is
391.Li -1
392and
393.Fa *tptrp
394is not
395.Dv NULL .
396.\"
397.Sh DIAGNOSTICS
398.Fn inet6_option_init
399and
400.Fn inet6_option_append
401return
402.Li 0
403on success or
404.Li -1
405on an error.
406.Pp
407.Fn inet6_option_alloc
408returns
409.Dv NULL on an error.
410.Pp
411On errors,
412.Fn inet6_option_next
413and
414.Fn inet6_option_find
415return
416.Li -1
417setting
418.Fa *tptrp
419to non
420.Dv NULL
421value.
422.\"
423.Sh EXAMPLES
424RFC2292 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
443The implementation first appeared in KAME advanced networking kit.
444.\"
445.Sh STANDARDS
446The functions are
447are documented in
448.Dq Advanced Sockets API for IPv6
449.Pq RFC2292 .
450.\"
451.Sh BUGS
452The text was shamelessly copied from RFC2292.