]> git.ipfire.org Git - thirdparty/strongswan.git/blame - doc/manpage.d/ipsec_satot.3.html
- import of strongswan-2.7.0
[thirdparty/strongswan.git] / doc / manpage.d / ipsec_satot.3.html
CommitLineData
997358a6
MW
1Content-type: text/html
2
3<HTML><HEAD><TITLE>Manpage of IPSEC_TTOSA</TITLE>
4</HEAD><BODY>
5<H1>IPSEC_TTOSA</H1>
6Section: C Library Functions (3)<BR>Updated: 26 Nov 2001<BR><A HREF="#index">Index</A>
7<A HREF="http://localhost/cgi-bin/man/man2html">Return to Main Contents</A><HR>
8
9
10<A NAME="lbAB">&nbsp;</A>
11<H2>NAME</H2>
12
13ipsec ttosa, satot - convert IPsec Security Association IDs to and from text
14<BR>
15
16ipsec initsaid - initialize an SA ID
17<A NAME="lbAC">&nbsp;</A>
18<H2>SYNOPSIS</H2>
19
20<B>#include &lt;<A HREF="file:/usr/include/freeswan.h">freeswan.h</A>&gt;</B>
21
22<P>
23<B>typedef struct {</B>
24
25<BR>
26&nbsp;
27<B>ip_address dst;</B>
28
29<BR>
30&nbsp;
31<B>ipsec_spi_t spi;</B>
32
33<BR>
34&nbsp;
35<B>int proto;</B>
36
37<BR>
38
39<B>} ip_said;</B>
40
41<P>
42<B>const char *ttosa(const char *src, size_t srclen,</B>
43
44<BR>
45&nbsp;
46<B>ip_said *sa);</B>
47
48<BR>
49
50<B>size_t satot(const ip_said *sa, int format,</B>
51
52<BR>
53&nbsp;
54<B>char *dst, size_t dstlen);</B>
55
56<BR>
57
58<B>void initsaid(const ip_address *addr, ipsec_spi_t spi,</B>
59
60<BR>
61&nbsp;
62<B>int proto, ip_said *dst);</B>
63
64<A NAME="lbAD">&nbsp;</A>
65<H2>DESCRIPTION</H2>
66
67<I>Ttosa</I>
68
69converts an ASCII Security Association (SA) specifier into an
70<B>ip_said</B>
71
72structure (containing
73a destination-host address
74in network byte order,
75an SPI number in network byte order, and
76a protocol code).
77<I>Satot</I>
78
79does the reverse conversion, back to a text SA specifier.
80<I>Initsaid</I>
81
82initializes an
83<B>ip_said</B>
84
85from separate items of information.
86<P>
87
88An SA is specified in text with a mail-like syntax, e.g.
89<B><A HREF="mailto:esp.5a7@1.2.3.4">esp.5a7@1.2.3.4</A></B>.
90
91An SA specifier contains
92a protocol prefix (currently
93<B>ah</B>,
94
95<B>esp</B>,
96
97<B>tun</B>,
98
99<B>comp</B>,
100
101or
102<B>int</B>),
103
104a single character indicating the address family
105(<B>.</B>
106
107for IPv4,
108<B>:</B>
109
110for IPv6),
111an unsigned integer SPI number in hexadecimal (with no
112<B>0x</B>
113
114prefix),
115and an IP address.
116The IP address can be any form accepted by
117<I><A HREF="ipsec_ttoaddr.3.html">ipsec_ttoaddr</A></I>(3),
118
119e.g. dotted-decimal IPv4 address,
120colon-hex IPv6 address,
121or DNS name.
122<P>
123
124As a special case, the SA specifier
125<B>%passthrough4</B>
126
127or
128<B>%passthrough6</B>
129
130signifies the special SA used to indicate that packets should be
131passed through unaltered.
132(At present, these are synonyms for
133<B><A HREF="mailto:tun.0@0.0.0.0">tun.0@0.0.0.0</A></B>
134
135and
136<B>tun:0@::</B>
137
138respectively,
139but that is subject to change without notice.)
140<B>%passthrough</B>
141
142is a historical synonym for
143<B>%passthrough4</B>.
144
145These forms are known to both
146<I>ttosa</I>
147
148and
149<I>satot</I>,
150
151so the internal representation is never visible.
152<P>
153
154Similarly, the SA specifiers
155<B>%pass</B>,
156
157<B>%drop</B>,
158
159<B>%reject</B>,
160
161<B>%hold</B>,
162
163<B>%trap</B>,
164
165and
166<B>%trapsubnet</B>
167
168signify special ``magic'' SAs used to indicate that packets should be
169passed, dropped, rejected (dropped with ICMP notification),
170held,
171and trapped (sent up to
172<I><A HREF="ipsec_pluto.8.html">ipsec_pluto</A></I>(8),
173
174with either of two forms of
175<B>%hold</B>
176
177automatically installed)
178respectively.
179These forms too are known to both routines,
180so the internal representation of the magic SAs should never be visible.
181<P>
182
183The
184<B>&lt;<A HREF="file:/usr/include/freeswan.h">freeswan.h</A>&gt;</B>
185
186header file supplies the
187<B>ip_said</B>
188
189structure, as well as a data type
190<B>ipsec_spi_t</B>
191
192which is an unsigned 32-bit integer.
193(There is no consistency between kernel and user on what such a type
194is called, hence the header hides the differences.)
195<P>
196
197The protocol code uses the same numbers that IP does.
198For user convenience, given the difficulty in acquiring the exact set of
199protocol names used by the kernel,
200<B>&lt;<A HREF="file:/usr/include/freeswan.h">freeswan.h</A>&gt;</B>
201
202defines the names
203<B>SA_ESP</B>,
204
205<B>SA_AH</B>,
206
207<B>SA_IPIP</B>,
208
209and
210<B>SA_COMP</B>
211
212to have the same values as the kernel names
213<B>IPPROTO_ESP</B>,
214
215<B>IPPROTO_AH</B>,
216
217<B>IPPROTO_IPIP</B>,
218
219and
220<B>IPPROTO_COMP</B>.
221
222<P>
223
224<B>&lt;<A HREF="file:/usr/include/freeswan.h">freeswan.h</A>&gt;</B>
225
226also defines
227<B>SA_INT</B>
228
229to have the value
230<B>61</B>
231
232(reserved by IANA for ``any host internal protocol'')
233and
234<B>SPI_PASS</B>,
235
236<B>SPI_DROP</B>,
237
238<B>SPI_REJECT</B>,
239
240<B>SPI_HOLD</B>,
241
242and
243<B>SPI_TRAP</B>
244
245to have the values 256-260 (in <I>host</I> byte order) respectively.
246These are used in constructing the magic SAs
247(which always have address
248<B>0.0.0.0</B>).
249
250<P>
251
252If
253<I>satot</I>
254
255encounters an unknown protocol code, e.g. 77,
256it yields output using a prefix
257showing the code numerically, e.g. ``unk77''.
258This form is
259<I>not</I>
260
261recognized by
262<I>ttosa</I>.
263
264<P>
265
266The
267<I>srclen</I>
268
269parameter of
270<I>ttosa</I>
271
272specifies the length of the string pointed to by
273<I>src</I>;
274
275it is an error for there to be anything else
276(e.g., a terminating NUL) within that length.
277As a convenience for cases where an entire NUL-terminated string is
278to be converted,
279a
280<I>srclen</I>
281
282value of
283<B>0</B>
284
285is taken to mean
286<B>strlen(src)</B>.
287
288<P>
289
290The
291<I>dstlen</I>
292
293parameter of
294<I>satot</I>
295
296specifies the size of the
297<I>dst</I>
298
299parameter;
300under no circumstances are more than
301<I>dstlen</I>
302
303bytes written to
304<I>dst</I>.
305
306A result which will not fit is truncated.
307<I>Dstlen</I>
308
309can be zero, in which case
310<I>dst</I>
311
312need not be valid and no result is written,
313but the return value is unaffected;
314in all other cases, the (possibly truncated) result is NUL-terminated.
315The
316<B>&lt;<A HREF="file:/usr/include/freeswan.h">freeswan.h</A>&gt;</B>
317
318header file defines a constant,
319<B>SATOT_BUF</B>,
320
321which is the size of a buffer just large enough for worst-case results.
322<P>
323
324The
325<I>format</I>
326
327parameter of
328<I>satot</I>
329
330specifies what format is to be used for the conversion.
331The value
332<B>0</B>
333
334(not the ASCII character
335<B>'0'</B>,
336
337but a zero value)
338specifies a reasonable default
339(currently
340lowercase protocol prefix, lowercase hexadecimal SPI,
341dotted-decimal or colon-hex address).
342The value
343<B>'f'</B>
344
345is similar except that the SPI is padded with
346<B>0</B>s
347
348to a fixed 32-bit width, to ease aligning displayed tables.
349<P>
350
351<I>Ttosa</I>
352
353returns
354<B>NULL</B>
355
356for success and
357a pointer to a string-literal error message for failure;
358see DIAGNOSTICS.
359<I>Satot</I>
360
361returns
362<B>0</B>
363
364for a failure, and otherwise
365always returns the size of buffer which would
366be needed to
367accommodate the full conversion result, including terminating NUL;
368it is the caller's responsibility to check this against the size of
369the provided buffer to determine whether truncation has occurred.
370<P>
371
372There is also, temporarily, support for some obsolete
373forms of SA specifier which lack the address-family indicator.
374<A NAME="lbAE">&nbsp;</A>
375<H2>SEE ALSO</H2>
376
377<A HREF="ipsec_ttoul.3.html">ipsec_ttoul</A>(3), <A HREF="ipsec_ttoaddr.3.html">ipsec_ttoaddr</A>(3), <A HREF="ipsec_samesaid.3.html">ipsec_samesaid</A>(3), <A HREF="inet.3.html">inet</A>(3)
378<A NAME="lbAF">&nbsp;</A>
379<H2>DIAGNOSTICS</H2>
380
381Fatal errors in
382<I>ttosa</I>
383
384are:
385empty input;
386input too small to be a legal SA specifier;
387no
388<B>@</B>
389
390in input;
391unknown protocol prefix;
392conversion error in
393<I>ttoul</I>
394
395or
396<I>ttoaddr</I>.
397
398<P>
399
400Fatal errors in
401<I>satot</I>
402
403are:
404unknown format.
405<A NAME="lbAG">&nbsp;</A>
406<H2>HISTORY</H2>
407
408Written for the FreeS/WAN project by Henry Spencer.
409<A NAME="lbAH">&nbsp;</A>
410<H2>BUGS</H2>
411
412The restriction of text-to-binary error reports to literal strings
413(so that callers don't need to worry about freeing them or copying them)
414does limit the precision of error reporting.
415<P>
416
417The text-to-binary error-reporting convention lends itself
418to slightly obscure code,
419because many readers will not think of NULL as signifying success.
420A good way to make it clearer is to write something like:
421<P>
422
423<DL COMPACT><DT><DD>
424<PRE>
425<B>const char *error;</B>
426
427<B>error = ttosa( /* ... */ );</B>
428<B>if (error != NULL) {</B>
429<B> /* something went wrong */</B>
430</PRE>
431
432</DL>
433
434<P>
435
436<HR>
437<A NAME="index">&nbsp;</A><H2>Index</H2>
438<DL>
439<DT><A HREF="#lbAB">NAME</A><DD>
440<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
441<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
442<DT><A HREF="#lbAE">SEE ALSO</A><DD>
443<DT><A HREF="#lbAF">DIAGNOSTICS</A><DD>
444<DT><A HREF="#lbAG">HISTORY</A><DD>
445<DT><A HREF="#lbAH">BUGS</A><DD>
446</DL>
447<HR>
448This document was created by
449<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
450using the manual pages.<BR>
451Time: 21:40:18 GMT, November 11, 2003
452</BODY>
453</HTML>