summaryrefslogtreecommitdiff
path: root/lib/libc/net/inet6_rthdr_space.3
blob: 439c2703572b2d5c7e6fc9faf4996c6424d80930 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
.\"	$OpenBSD: inet6_rthdr_space.3,v 1.4 2000/01/18 21:49:01 aaron Exp $
.\"
.\" Copyright (c) 1983, 1987, 1991, 1993
.\"	The Regents of the University of California.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"	This product includes software developed by the University of
.\"	California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"     From: @(#)gethostbyname.3	8.4 (Berkeley) 5/25/95
.\"     KAME Id: inet6_rthdr_space.3,v 1.3 1999/12/12 14:58:04 itojun Exp
.\"
.Dd December 10, 1999
.Dt INET6_OPTION_SPACE 3
.Os
.\"
.Sh NAME
.Nm inet6_rthdr_space ,
.Nm inet6_rthdr_init ,
.Nm inet6_rthdr_add ,
.Nm inet6_rthdr_lasthop ,
.Nm inet6_rthdr_reverse ,
.Nm inet6_rthdr_segments ,
.Nm inet6_rthdr_getaddr ,
.Nm inet6_rthdr_getflags
.Nd IPv6 Routing Header Options manipulation
.\"
.Sh SYNOPSIS
.Fd #include <netinet/in.h>
.Ft size_t
.Fn inet6_rthdr_space "int type" "int segments"
.Ft "struct cmsghdr *"
.Fn inet6_rthdr_init "void *bp" "int type"
.Ft int
.Fn inet6_rthdr_add "struct cmsghdr *cmsg" "const struct in6_addr *addr" "unsigned int flags"
.Ft int
.Fn inet6_rthdr_lasthop "struct cmsghdr *cmsg" "unsigned int flags"
.Ft int
.Fn inet6_rthdr_reverse "const struct cmsghdr *in" "struct cmsghdr *out"
.Ft int
.Fn inet6_rthdr_segments "const struct cmsghdr *cmsg"
.Ft "struct in6_addr"
.Fn inet6_rthdr_getaddr "struct cmsghdr *cmsg" "int index"
.Ft int
.Fn inet6_rthdr_getflags "const struct cmsghdr *cmsg" "int index"
.\"
.Sh DESCRIPTION
RFC2292 IPv6 advanced API defines eight
functions that the application calls to build and examine a Routing
header.  Four functions build a Routing header:
.Bl -hang
.It Fn inet6_rthdr_space
return #bytes required for ancillary data
.It Fn inet6_rthdr_init
initialize ancillary data for Routing header
.It Fn inet6_rthdr_add
add IPv6 address & flags to Routing header
.It Fn inet6_rthdr_lasthop
specify the flags for the final hop
.El
.Pp
Four functions deal with a returned Routing header:
.Bl -hang
.It Fn inet6_rthdr_reverse
reverse a Routing header
.It Fn inet6_rthdr_segments
return #segments in a Routing header
.It Fn inet6_rthdr_getaddr
fetch one address from a Routing header
.It Fn inet6_rthdr_getflags
fetch one flag from a Routing header
.El
.Pp
The function prototypes for these functions are all in the
.Aq Li netinet/in.h
header.
.\"
.Ss inet6_rthdr_space
This function returns the number of bytes required to hold a Routing
header of the specified
.Fa type
containing the specified number of
.Fa segments
.Pq addresses .
For an IPv6 Type 0 Routing header, the number
of segments must be between 1 and 23, inclusive.  The return value
includes the size of the cmsghdr structure that precedes the Routing
header, and any required padding.
.Pp
If the return value is 0, then either the type of the Routing header
is not supported by this implementation or the number of segments is
invalid for this type of Routing header.
.Pp
Note: This function returns the size but does not allocate the space
required for the ancillary data.
This allows an application to
allocate a larger buffer, if other ancillary data objects are
desired, since all the ancillary data objects must be specified to
.Xr sendmsg 2
as a single
.Li msg_control
buffer.
.\"
.Ss inet6_rthdr_init
This function initializes the buffer pointed to by
.Fa bp
to contain a
.Li cmsghdr
structure followed by a Routing header of the specified
.Fa type .
The
.Li cmsg_len
member of the
.Li cmsghdr
structure is initialized to the
size of the structure plus the amount of space required by the
Routing header.
The
.Li cmsg_level
and
.Li cmsg_type
members are also initialized as required.
.Pp
The caller must allocate the buffer and its size can be determined by
calling
.Fn inet6_rthdr_space .
.Pp
Upon success the return value is the pointer to the
.Li cmsghdr
structure, and this is then used as the first argument to the next
two functions.
Upon an error the return value is
.Dv NULL .
.\"
.Ss inet6_rthdr_add
This function adds the address pointed to by
.Fa addr
to the end of the
Routing header being constructed and sets the type of this hop to the
value of
.Fa flags .
For an IPv6 Type 0 Routing header,
.Fa flags
must be
either
.Dv IPV6_RTHDR_LOOSE
or
.Dv IPV6_RTHDR_STRICT .
.Pp
If successful, the
.Li cmsg_len
member of the
.Li cmsghdr
structure is
updated to account for the new address in the Routing header and the
return value of the function is 0.
Upon an error the return value of
the function is -1.
.\"
.Ss inet6_rthdr_lasthop
This function specifies the Strict/Loose flag for the final hop of a
Routing header.
For an IPv6 Type 0 Routing header,
.Fa flags
must be either
.Dv IPV6_RTHDR_LOOSE
or
.Dv IPV6_RTHDR_STRICT .
.Pp
The return value of the function is 0 upon success, or -1 upon an error.
.Pp
Notice that a Routing header specifying
.Li N
intermediate nodes requires
.Li N+1
Strict/Loose flags.
This requires
.Li N
calls to
.Fn inet6_rthdr_add
followed by one call to
.Fn inet6_rthdr_lasthop .
.\"
.Ss inet6_rthdr_reverse
This function takes a Routing header that was received as ancillary
data
.Po
pointed to by the first argument,
.Fa in
.Pc
and writes a new Routing
header that sends datagrams along the reverse of that route.
Both
arguments are allowed to point to the same buffer
.Pq that is, the reversal can occur in place .
.Pp
The return value of the function is 0 on success, or -1 upon an
error.
.\"
.Ss inet6_rthdr_segments
This function returns the number of segments
.Pq addresses
contained in
the Routing header described by
.Fa cmsg .
On success the return value is
between 1 and 23, inclusive.
The return value of the function is -1 upon an error.
.\"
.Ss inet6_rthdr_getaddr
This function returns a pointer to the IPv6 address specified by
.Fa index
.Po
which must have a value between 1 and the value returned by
.Fn inet6_rthdr_segments
.Pc
in the Routing header described by
.Fa cmsg .
An
application should first call
.Fn inet6_rthdr_segments
to obtain the number of segments in the Routing header.
.Pp
Upon an error the return value of the function is
.Dv NULL .
.\"
.Ss inet6_rthdr_getflags
This function returns the flags value specified by
.Fa index
.Po
which must
have a value between 0 and the value returned by
.Fn inet6_rthdr_segments
.Pc
in the Routing header described by
.Fa cmsg .
For an IPv6 Type 0 Routing header the return value will be either
.Dv IPV6_RTHDR_LOOSE
or
.Dv IPV6_RTHDR_STRICT .
.Pp
Upon an error the return value of the function is -1.
.Pp
Note: Addresses are indexed starting at 1, and flags starting at 0,
to maintain consistency with the terminology and figures in RFC2460.
.\"
.Sh DIAGNOSTICS
.Fn inet6_rthdr_space
returns 0 on errors.
.Pp
.Fn inet6_rthdr_add ,
.Fn inet6_rthdr_lasthop
and
.Fn inet6_rthdr_reverse
return 0 on success, and returns -1 on error.
.Pp
.Fn inet6_rthdr_init
and
.Fn inet6_rthdr_getaddr
return
.Dv NULL
on error.
.Pp
.Fn inet6_rthdr_segments
and
.Fn inet6_rthdr_getflags
return -1 on error.
.\"
.Sh EXAMPLES
RFC2292 gives comprehensive examples in chapter 8.
.\"
.Sh SEE ALSO
.Rs
.%A W. Stevens
.%A M. Thomas
.%T "Advanced Sockets API for IPv6"
.%N RFC2292
.%D February 1998
.Re
.Rs
.%A S. Deering
.%A R. Hinden
.%T "Internet Protocol, Version 6 (IPv6) Specification"
.%N RFC2460
.%D December 1998
.Re
.\"
.Sh HISTORY
The implementation first appeared in KAME advanced networking kit.
.\"
.Sh STANDARDS
The functions
are documented in
.Dq Advanced Sockets API for IPv6
.Pq RFC2292 .
.\"
.Sh BUGS
The text was shamelessly copied from RFC2292.
.Pp
.Fn inet6_rthdr_reverse
is not implemented yet.