summaryrefslogtreecommitdiff
path: root/lib/libc/net/inet6_rth_space.3
blob: 326521def74b0a1fd7ccb764f26231dc46ae5a35 (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
.\"	$OpenBSD: inet6_rth_space.3,v 1.3 2007/05/31 19:19:30 jmc Exp $
.\"	$KAME: inet6_rth_space.3,v 1.7 2005/01/05 03:00:44 itojun Exp $
.\"
.\" Copyright (C) 2004 WIDE Project.
.\" 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. Neither the name of the project 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 PROJECT 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 PROJECT 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.
.\"
.Dd $Mdocdate: May 31 2007 $
.Dt INET6_RTH_SPACE 3
.Os
.\"
.Sh NAME
.Nm inet6_rth_space ,
.Nm inet6_rth_init ,
.Nm inet6_rth_add ,
.Nm inet6_rth_reverse ,
.Nm inet6_rth_segments ,
.Nm inet6_rth_getaddr
.Nd IPv6 Routing Header Options manipulation
.\"
.Sh SYNOPSIS
.In netinet/in.h
.Ft socklen_t
.Fn inet6_rth_space "int" "int"
.Ft "void *"
.Fn inet6_rth_init "void *" "socklen_t" "int" "int"
.Ft int
.Fn inet6_rth_add "void *" "const struct in6_addr *"
.Ft int
.Fn inet6_rth_reverse "const void *" "void *"
.Ft int
.Fn inet6_rth_segments "const void *"
.Ft "struct in6_addr *"
.Fn inet6_rth_getaddr "const void *" "int"
.\"
.Sh DESCRIPTION
The IPv6 Advanced API, RFC 3542, defines the functions that an
application calls to build and examine IPv6 Routing headers.
Routing headers are used to perform source routing in IPv6 networks.
The RFC uses the word
.Dq segments
to describe addresses and that is the term used here as well.
All of the functions are defined in the header file
.Aq Pa netinet/in.h .
The functions described in this manual page all operate
on routing header structures which are defined in
.Aq Pa netinet/ip6.h
but which should not need to be modified outside the use of this API.
The size and shape of the route header structures may change, so using
the APIs is a more portable, long term, solution.
.Pp
The functions in the API are split into two groups, those that build a
routing header and those that parse a received routing header.
The builder functions are described first, followed by the parser functions.
.Ss inet6_rth_space
The
.Fn inet6_rth_space
function returns the number of bytes required to hold a Routing Header
of the type, specified in the
.Fa type
argument and containing the number of addresses specified in the
.Fa segments
argument.
When the type is
.Dv IPV6_RTHDR_TYPE_0
the number of segments must be from 0 through 127.
The return value from this function is the number of bytes required to
store the routing header.
If the value 0 is returned then either the
route header type was not recognized or another error occurred.
.Ss inet6_rth_init
The
.Fn inet6_rth_init
function initializes the pre-allocated buffer pointed to by
.Fa bp
to contain a routing header of the specified type.
The
.Fa bp_len
argument is used to verify that the buffer is large enough.
The caller must allocate the buffer pointed to by bp.
The necessary buffer size should be determined by calling
.Fn inet6_rth_space
described in the previous sections.
.Pp
The
.Fn inet6_rth_init
function returns a pointer to
.Fa bp
on success and
.Dv NULL
when there is an error.
.Ss inet6_rth_add
The
.Fn inet6_rth_add
function adds the IPv6 address pointed to by
.Fa addr
to the end of the routing header being constructed.
.Pp
A successful addition results in the function returning 0, otherwise
\-1 is returned.
.Ss inet6_rth_reverse
The
.Fn inet6_rth_reverse
function takes a routing header, pointed to by the
argument
.Fa in ,
and writes a new routing header into the argument pointed to by
.Fa out .
The routing header at that sends datagrams along the reverse of that
route.
Both arguments are allowed to point to the same buffer meaning
that the reversal can occur in place.
.Pp
The return value of the function is 0 on success, or \-1 when
there is an error.
.\"
.Pp
The next set of functions operate on a routing header that the
application wants to parse.
In the usual case such a routing header
is received from the network, although these functions can also be
used with routing headers that the application itself created.
.Ss inet6_rth_segments
The
.Fn inet6_rth_segments
function returns the number of segments contained in the
routing header pointed to by
.Fa bp .
The return value is the number of segments contained in the routing
header, or \-1 if an error occurred.
It is not an error for 0 to be
returned as a routing header may contain 0 segments.
.\"
.Ss inet6_rth_getaddr
The
.Fn inet6_rth_getaddr
function is used to retrieve a single address from a routing header.
The
.Fa index
is the location in the routing header from which the application wants
to retrieve an address.
The
.Fa index
parameter must have a value between 0 and one less than the number of
segments present in the routing header.
The
.Fn inet6_rth_segments
function, described in the last section, should be used to determine
the total number of segments in the routing header.
The
.Fn inet6_rth_getaddr
function returns a pointer to an IPv6 address on success or
.Dv NULL
when an error has occurred.
.\"
.Sh EXAMPLES
RFC 3542 gives extensive examples in Section 21, Appendix B.
KAME also provides examples in the advapitest directory of its kit.
.\"
.Sh DIAGNOSTICS
The
.Fn inet6_rth_space
and
.Fn inet6_rth_getaddr
functions return 0 on errors.
.Pp
The
.Fn inet6_rthdr_init
function returns
.Dv NULL
on error.
The
.Fn inet6_rth_add
and
.Fn inet6_rth_reverse
functions return 0 on success, or \-1 upon an error.
.\"
.Sh SEE ALSO
.Rs
.%A W. Stevens
.%A M. Thomas
.%A E. Nordmark
.%A T. Jinmei
.%T "Advanced Sockets API for IPv6"
.%N RFC 3542
.%D May 2003
.Re
.Rs
.%A S. Deering
.%A R. Hinden
.%T "Internet Protocol, Version 6 (IPv6) Specification"
.%N RFC 2460
.%D December 1998
.Re
.Sh HISTORY
The implementation first appeared in KAME advanced networking kit.