xref: /netbsd-src/crypto/dist/ipsec-tools/src/libipsec/ipsec_strerror.c (revision ba30b496b84a2848bd2134d385edb439c2482585)
1*ba30b496Svanhu /*	$NetBSD: ipsec_strerror.c,v 1.6 2010/04/07 14:53:52 vanhu Exp $	*/
28006965bSmanu 
3a8f0ad3cSmanu /*	$KAME: ipsec_strerror.c,v 1.7 2000/07/30 00:45:12 itojun Exp $	*/
4a8f0ad3cSmanu 
5a8f0ad3cSmanu /*
6a8f0ad3cSmanu  * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
7a8f0ad3cSmanu  * All rights reserved.
8a8f0ad3cSmanu  *
9a8f0ad3cSmanu  * Redistribution and use in source and binary forms, with or without
10a8f0ad3cSmanu  * modification, are permitted provided that the following conditions
11a8f0ad3cSmanu  * are met:
12a8f0ad3cSmanu  * 1. Redistributions of source code must retain the above copyright
13a8f0ad3cSmanu  *    notice, this list of conditions and the following disclaimer.
14a8f0ad3cSmanu  * 2. Redistributions in binary form must reproduce the above copyright
15a8f0ad3cSmanu  *    notice, this list of conditions and the following disclaimer in the
16a8f0ad3cSmanu  *    documentation and/or other materials provided with the distribution.
17a8f0ad3cSmanu  * 3. Neither the name of the project nor the names of its contributors
18a8f0ad3cSmanu  *    may be used to endorse or promote products derived from this software
19a8f0ad3cSmanu  *    without specific prior written permission.
20a8f0ad3cSmanu  *
21a8f0ad3cSmanu  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22a8f0ad3cSmanu  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23a8f0ad3cSmanu  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24a8f0ad3cSmanu  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25a8f0ad3cSmanu  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26a8f0ad3cSmanu  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27a8f0ad3cSmanu  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28a8f0ad3cSmanu  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29a8f0ad3cSmanu  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30a8f0ad3cSmanu  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31a8f0ad3cSmanu  * SUCH DAMAGE.
32a8f0ad3cSmanu  */
33a8f0ad3cSmanu 
34a8f0ad3cSmanu #ifdef HAVE_CONFIG_H
35a8f0ad3cSmanu #include "config.h"
36a8f0ad3cSmanu #endif
37a8f0ad3cSmanu 
38a8f0ad3cSmanu #include <sys/types.h>
39a8f0ad3cSmanu #include <sys/param.h>
40a8f0ad3cSmanu 
41a8f0ad3cSmanu #include <string.h>
42c3bc7fe3Svanhu #include PATH_IPSEC_H
43a8f0ad3cSmanu 
44a8f0ad3cSmanu #include "ipsec_strerror.h"
45a8f0ad3cSmanu 
46a8f0ad3cSmanu int __ipsec_errcode;
47a8f0ad3cSmanu 
48a8f0ad3cSmanu static const char *ipsec_errlist[] = {
49a8f0ad3cSmanu "Success",					/*EIPSEC_NO_ERROR*/
50a8f0ad3cSmanu "Not supported",				/*EIPSEC_NOT_SUPPORTED*/
51a8f0ad3cSmanu "Invalid argument",				/*EIPSEC_INVAL_ARGUMENT*/
52a8f0ad3cSmanu "Invalid sadb message",				/*EIPSEC_INVAL_SADBMSG*/
53a8f0ad3cSmanu "Invalid version",				/*EIPSEC_INVAL_VERSION*/
54a8f0ad3cSmanu "Invalid security policy",			/*EIPSEC_INVAL_POLICY*/
55a8f0ad3cSmanu "Invalid address specification",		/*EIPSEC_INVAL_ADDRESS*/
56a8f0ad3cSmanu "Invalid ipsec protocol",			/*EIPSEC_INVAL_PROTO*/
57a8f0ad3cSmanu "Invalid ipsec mode",				/*EIPSEC_INVAL_MODE*/
58a8f0ad3cSmanu "Invalid ipsec level",				/*EIPSEC_INVAL_LEVEL*/
59a8f0ad3cSmanu "Invalid SA type",				/*EIPSEC_INVAL_SATYPE*/
60a8f0ad3cSmanu "Invalid message type",				/*EIPSEC_INVAL_MSGTYPE*/
61a8f0ad3cSmanu "Invalid extension type",			/*EIPSEC_INVAL_EXTTYPE*/
62a8f0ad3cSmanu "Invalid algorithm type",			/*EIPSEC_INVAL_ALGS*/
63a8f0ad3cSmanu "Invalid key length",				/*EIPSEC_INVAL_KEYLEN*/
64a8f0ad3cSmanu "Invalid address family",			/*EIPSEC_INVAL_FAMILY*/
65a8f0ad3cSmanu "Invalid prefix length",			/*EIPSEC_INVAL_PREFIXLEN*/
66*ba30b496Svanhu "Invalid direction",				/*EIPSEC_INVAL_DIR*/
67a8f0ad3cSmanu "SPI range violation",				/*EIPSEC_INVAL_SPI*/
68a8f0ad3cSmanu "No protocol specified",			/*EIPSEC_NO_PROTO*/
69a8f0ad3cSmanu "No algorithm specified",			/*EIPSEC_NO_ALGS*/
70a8f0ad3cSmanu "No buffers available",				/*EIPSEC_NO_BUFS*/
71a8f0ad3cSmanu "Must get supported algorithms list first",	/*EIPSEC_DO_GET_SUPP_LIST*/
72a8f0ad3cSmanu "Protocol mismatch",				/*EIPSEC_PROTO_MISMATCH*/
73a8f0ad3cSmanu "Family mismatch",				/*EIPSEC_FAMILY_MISMATCH*/
74a8f0ad3cSmanu "Too few arguments",				/*EIPSEC_FEW_ARGUMENTS*/
75a8f0ad3cSmanu NULL,						/*EIPSEC_SYSTEM_ERROR*/
76a8f0ad3cSmanu "Priority offset not in valid range [-2147483647, 2147483648]",	/*EIPSEC_INVAL_PRIORITY_OFFSET*/
77a8f0ad3cSmanu "Priority offset from base not in valid range [0, 1073741823] for negative offsets and [0, 1073741824] for positive offsets", /* EIPSEC_INVAL_PRIORITY_OFFSET */
78a8f0ad3cSmanu "Policy priority not compiled in",	/*EIPSEC_PRIORITY_NOT_COMPILED*/
79a8f0ad3cSmanu "Unknown error",				/*EIPSEC_MAX*/
80a8f0ad3cSmanu };
81a8f0ad3cSmanu 
ipsec_strerror(void)82a8f0ad3cSmanu const char *ipsec_strerror(void)
83a8f0ad3cSmanu {
84a8f0ad3cSmanu 	if (__ipsec_errcode < 0 || __ipsec_errcode > EIPSEC_MAX)
85a8f0ad3cSmanu 		__ipsec_errcode = EIPSEC_MAX;
86a8f0ad3cSmanu 
87a8f0ad3cSmanu 	return ipsec_errlist[__ipsec_errcode];
88a8f0ad3cSmanu }
89a8f0ad3cSmanu 
__ipsec_set_strerror(const char * str)90a8f0ad3cSmanu void __ipsec_set_strerror(const char *str)
91a8f0ad3cSmanu {
92a8f0ad3cSmanu 	__ipsec_errcode = EIPSEC_SYSTEM_ERROR;
93a8f0ad3cSmanu 	ipsec_errlist[EIPSEC_SYSTEM_ERROR] = str;
94a8f0ad3cSmanu 
95a8f0ad3cSmanu 	return;
96a8f0ad3cSmanu }
97