• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*	$NetBSD: strnames.c,v 1.7.6.1 2007/08/01 11:52:22 vanhu Exp $	*/
2 
3 /*	$KAME: strnames.c,v 1.25 2003/11/13 10:53:26 itojun Exp $	*/
4 
5 /*
6  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. Neither the name of the project nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 
34 #include "config.h"
35 
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/socket.h>
39 
40 #include <netinet/in.h>
41 #include PATH_IPSEC_H
42 #include <netinet/in.h>
43 
44 #include <stdio.h>
45 #include <stdlib.h>
46 #ifdef ENABLE_HYBRID
47 #include <resolv.h>
48 #endif
49 
50 #include "var.h"
51 #include "misc.h"
52 #include "vmbuf.h"
53 #include "plog.h"
54 
55 #include "isakmp_var.h"
56 #include "isakmp.h"
57 #ifdef ENABLE_HYBRID
58 #  include "isakmp_xauth.h"
59 #  include "isakmp_unity.h"
60 #  include "isakmp_cfg.h"
61 #endif
62 #include "ipsec_doi.h"
63 #include "oakley.h"
64 #include "handler.h"
65 #include "pfkey.h"
66 #include "strnames.h"
67 #include "algorithm.h"
68 
69 struct ksmap {
70 	int key;
71 	char *str;
72 	char *(*f) __P((int));
73 };
74 
75 char *
num2str(n)76 num2str(n)
77 	int n;
78 {
79 	static char buf[20];
80 
81 	snprintf(buf, sizeof(buf), "%d", n);
82 
83 	return buf;
84 }
85 
86 /* isakmp.h */
87 char *
s_isakmp_state(t,d,s)88 s_isakmp_state(t, d, s)
89 	int t, d, s;
90 {
91 	switch (t) {
92 	case ISAKMP_ETYPE_AGG:
93 		switch (d) {
94 		case INITIATOR:
95 			switch (s) {
96 			case PHASE1ST_MSG1SENT:
97 				return "agg I msg1";
98 			case PHASE1ST_ESTABLISHED:
99 				return "agg I msg2";
100 			default:
101 				break;
102 			}
103 		case RESPONDER:
104 			switch (s) {
105 			case PHASE1ST_MSG1SENT:
106 				return "agg R msg1";
107 			default:
108 				break;
109 			}
110 		}
111 		break;
112 	case ISAKMP_ETYPE_BASE:
113 		switch (d) {
114 		case INITIATOR:
115 			switch (s) {
116 			case PHASE1ST_MSG1SENT:
117 				return "base I msg1";
118 			case PHASE1ST_MSG2SENT:
119 				return "base I msg2";
120 			default:
121 				break;
122 			}
123 		case RESPONDER:
124 			switch (s) {
125 			case PHASE1ST_MSG1SENT:
126 				return "base R msg1";
127 			case PHASE1ST_ESTABLISHED:
128 				return "base R msg2";
129 			default:
130 				break;
131 			}
132 		}
133 		break;
134 	case ISAKMP_ETYPE_IDENT:
135 		switch (d) {
136 		case INITIATOR:
137 			switch (s) {
138 			case PHASE1ST_MSG1SENT:
139 				return "ident I msg1";
140 			case PHASE1ST_MSG2SENT:
141 				return "ident I msg2";
142 			case PHASE1ST_MSG3SENT:
143 				return "ident I msg3";
144 			default:
145 				break;
146 			}
147 		case RESPONDER:
148 			switch (s) {
149 			case PHASE1ST_MSG1SENT:
150 				return "ident R msg1";
151 			case PHASE1ST_MSG2SENT:
152 				return "ident R msg2";
153 			case PHASE1ST_ESTABLISHED:
154 				return "ident R msg3";
155 			default:
156 				break;
157 			}
158 		}
159 		break;
160 	case ISAKMP_ETYPE_QUICK:
161 		switch (d) {
162 		case INITIATOR:
163 			switch (s) {
164 			case PHASE2ST_MSG1SENT:
165 				return "quick I msg1";
166 			case PHASE2ST_ADDSA:
167 				return "quick I msg2";
168 			default:
169 				break;
170 			}
171 		case RESPONDER:
172 			switch (s) {
173 			case PHASE2ST_MSG1SENT:
174 				return "quick R msg1";
175 			case PHASE2ST_COMMIT:
176 				return "quick R msg2";
177 			default:
178 				break;
179 			}
180 		}
181 		break;
182 	default:
183 	case ISAKMP_ETYPE_NONE:
184 	case ISAKMP_ETYPE_AUTH:
185 	case ISAKMP_ETYPE_INFO:
186 	case ISAKMP_ETYPE_NEWGRP:
187 	case ISAKMP_ETYPE_ACKINFO:
188 		break;
189 	}
190 	/*NOTREACHED*/
191 
192 	return "???";
193 }
194 
195 static struct ksmap name_isakmp_certtype[] = {
196 { ISAKMP_CERT_NONE,	"NONE",					NULL },
197 { ISAKMP_CERT_PKCS7,	"PKCS #7 wrapped X.509 certificate",	NULL },
198 { ISAKMP_CERT_PGP,	"PGP Certificate",			NULL },
199 { ISAKMP_CERT_DNS,	"DNS Signed Key",			NULL },
200 { ISAKMP_CERT_X509SIGN,	"X.509 Certificate Signature",		NULL },
201 { ISAKMP_CERT_X509KE,	"X.509 Certificate Key Exchange",	NULL },
202 { ISAKMP_CERT_KERBEROS,	"Kerberos Tokens",			NULL },
203 { ISAKMP_CERT_CRL,	"Certificate Revocation List (CRL)",	NULL },
204 { ISAKMP_CERT_ARL,	"Authority Revocation List (ARL)",	NULL },
205 { ISAKMP_CERT_SPKI,	"SPKI Certificate",			NULL },
206 { ISAKMP_CERT_X509ATTR,	"X.509 Certificate Attribute",		NULL },
207 };
208 
209 char *
s_isakmp_certtype(k)210 s_isakmp_certtype(k)
211 	int k;
212 {
213 	int i;
214 	for (i = 0; i < ARRAYLEN(name_isakmp_certtype); i++)
215 		if (name_isakmp_certtype[i].key == k)
216 			return name_isakmp_certtype[i].str;
217 	return num2str(k);
218 }
219 
220 static struct ksmap name_isakmp_etype[] = {
221 { ISAKMP_ETYPE_NONE,	"None",			NULL },
222 { ISAKMP_ETYPE_BASE,	"Base",			NULL },
223 { ISAKMP_ETYPE_IDENT,	"Identity Protection",	NULL },
224 { ISAKMP_ETYPE_AUTH,	"Authentication Only",	NULL },
225 { ISAKMP_ETYPE_AGG,	"Aggressive",		NULL },
226 { ISAKMP_ETYPE_INFO,	"Informational",	NULL },
227 { ISAKMP_ETYPE_CFG,	"Mode config",		NULL },
228 { ISAKMP_ETYPE_QUICK,	"Quick",		NULL },
229 { ISAKMP_ETYPE_NEWGRP,	"New Group",		NULL },
230 { ISAKMP_ETYPE_ACKINFO,	"Acknowledged Informational",	NULL },
231 };
232 
233 char *
s_isakmp_etype(k)234 s_isakmp_etype(k)
235 	int k;
236 {
237 	int i;
238 	for (i = 0; i < ARRAYLEN(name_isakmp_etype); i++)
239 		if (name_isakmp_etype[i].key == k)
240 			return name_isakmp_etype[i].str;
241 	return num2str(k);
242 }
243 
244 static struct ksmap name_isakmp_notify_msg[] = {
245 { ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE,	"INVALID-PAYLOAD-TYPE",		NULL },
246 { ISAKMP_NTYPE_DOI_NOT_SUPPORTED,	"DOI-NOT-SUPPORTED",		NULL },
247 { ISAKMP_NTYPE_SITUATION_NOT_SUPPORTED,	"SITUATION-NOT-SUPPORTED",	NULL },
248 { ISAKMP_NTYPE_INVALID_COOKIE,		"INVALID-COOKIE",		NULL },
249 { ISAKMP_NTYPE_INVALID_MAJOR_VERSION,	"INVALID-MAJOR-VERSION",	NULL },
250 { ISAKMP_NTYPE_INVALID_MINOR_VERSION,	"INVALID-MINOR-VERSION",	NULL },
251 { ISAKMP_NTYPE_INVALID_EXCHANGE_TYPE,	"INVALID-EXCHANGE-TYPE",	NULL },
252 { ISAKMP_NTYPE_INVALID_FLAGS,		"INVALID-FLAGS",		NULL },
253 { ISAKMP_NTYPE_INVALID_MESSAGE_ID,	"INVALID-MESSAGE-ID",		NULL },
254 { ISAKMP_NTYPE_INVALID_PROTOCOL_ID,	"INVALID-PROTOCOL-ID",		NULL },
255 { ISAKMP_NTYPE_INVALID_SPI,		"INVALID-SPI",			NULL },
256 { ISAKMP_NTYPE_INVALID_TRANSFORM_ID,	"INVALID-TRANSFORM-ID",		NULL },
257 { ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED, "ATTRIBUTES-NOT-SUPPORTED",	NULL },
258 { ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN,	"NO-PROPOSAL-CHOSEN",		NULL },
259 { ISAKMP_NTYPE_BAD_PROPOSAL_SYNTAX,	"BAD-PROPOSAL-SYNTAX",		NULL },
260 { ISAKMP_NTYPE_PAYLOAD_MALFORMED,	"PAYLOAD-MALFORMED",		NULL },
261 { ISAKMP_NTYPE_INVALID_KEY_INFORMATION,	"INVALID-KEY-INFORMATION",	NULL },
262 { ISAKMP_NTYPE_INVALID_ID_INFORMATION,	"INVALID-ID-INFORMATION",	NULL },
263 { ISAKMP_NTYPE_INVALID_CERT_ENCODING,	"INVALID-CERT-ENCODING",	NULL },
264 { ISAKMP_NTYPE_INVALID_CERTIFICATE,	"INVALID-CERTIFICATE",		NULL },
265 { ISAKMP_NTYPE_BAD_CERT_REQUEST_SYNTAX,	"BAD-CERT-REQUEST-SYNTAX",	NULL },
266 { ISAKMP_NTYPE_INVALID_CERT_AUTHORITY,	"INVALID-CERT-AUTHORITY",	NULL },
267 { ISAKMP_NTYPE_INVALID_HASH_INFORMATION, "INVALID-HASH-INFORMATION",	NULL },
268 { ISAKMP_NTYPE_AUTHENTICATION_FAILED,	"AUTHENTICATION-FAILED",	NULL },
269 { ISAKMP_NTYPE_INVALID_SIGNATURE,	"INVALID-SIGNATURE",		NULL },
270 { ISAKMP_NTYPE_ADDRESS_NOTIFICATION,	"ADDRESS-NOTIFICATION",		NULL },
271 { ISAKMP_NTYPE_NOTIFY_SA_LIFETIME,	"NOTIFY-SA-LIFETIME",		NULL },
272 { ISAKMP_NTYPE_CERTIFICATE_UNAVAILABLE,	"CERTIFICATE-UNAVAILABLE",	NULL },
273 { ISAKMP_NTYPE_UNSUPPORTED_EXCHANGE_TYPE, "UNSUPPORTED-EXCHANGE-TYPE",	NULL },
274 { ISAKMP_NTYPE_UNEQUAL_PAYLOAD_LENGTHS,	"UNEQUAL-PAYLOAD-LENGTHS",	NULL },
275 { ISAKMP_NTYPE_CONNECTED,		"CONNECTED",			NULL },
276 { ISAKMP_NTYPE_RESPONDER_LIFETIME,	"RESPONDER-LIFETIME",		NULL },
277 { ISAKMP_NTYPE_REPLAY_STATUS,		"REPLAY-STATUS",		NULL },
278 { ISAKMP_NTYPE_INITIAL_CONTACT,		"INITIAL-CONTACT",		NULL },
279 #ifdef ENABLE_HYBRID
280 { ISAKMP_NTYPE_UNITY_HEARTBEAT,		"HEARTBEAT (Unity)",		NULL },
281 #endif
282 { ISAKMP_LOG_RETRY_LIMIT_REACHED,	"RETRY-LIMIT-REACHED",		NULL },
283 };
284 
285 char *
s_isakmp_notify_msg(k)286 s_isakmp_notify_msg(k)
287 	int k;
288 {
289 	int i;
290 	for (i = 0; i < ARRAYLEN(name_isakmp_notify_msg); i++)
291 		if (name_isakmp_notify_msg[i].key == k)
292 			return name_isakmp_notify_msg[i].str;
293 
294 	return num2str(k);
295 }
296 
297 static struct ksmap name_isakmp_nptype[] = {
298 { ISAKMP_NPTYPE_NONE,		"none",		NULL },
299 { ISAKMP_NPTYPE_SA,		"sa",		NULL },
300 { ISAKMP_NPTYPE_P,		"prop",		NULL },
301 { ISAKMP_NPTYPE_T,		"trns",		NULL },
302 { ISAKMP_NPTYPE_KE,		"ke",		NULL },
303 { ISAKMP_NPTYPE_ID,		"id",		NULL },
304 { ISAKMP_NPTYPE_CERT,		"cert",		NULL },
305 { ISAKMP_NPTYPE_CR,		"cr",		NULL },
306 { ISAKMP_NPTYPE_HASH,		"hash",		NULL },
307 { ISAKMP_NPTYPE_SIG,		"sig",		NULL },
308 { ISAKMP_NPTYPE_NONCE,		"nonce",	NULL },
309 { ISAKMP_NPTYPE_N,		"notify",	NULL },
310 { ISAKMP_NPTYPE_D,		"delete",	NULL },
311 { ISAKMP_NPTYPE_VID,		"vid",		NULL },
312 { ISAKMP_NPTYPE_ATTR,		"attr",		NULL },
313 { ISAKMP_NPTYPE_GSS,		"gss id",	NULL },
314 { ISAKMP_NPTYPE_NATD_RFC,	"nat-d",	NULL },
315 { ISAKMP_NPTYPE_NATOA_RFC,	"nat-oa",	NULL },
316 { ISAKMP_NPTYPE_NATD_DRAFT,	"nat-d",	NULL },
317 { ISAKMP_NPTYPE_NATOA_DRAFT,	"nat-oa",	NULL },
318 { ISAKMP_NPTYPE_FRAG,		"ike frag",	NULL },
319 };
320 
321 char *
s_isakmp_nptype(k)322 s_isakmp_nptype(k)
323 	int k;
324 {
325 	int i;
326 	for (i = 0; i < ARRAYLEN(name_isakmp_nptype); i++)
327 		if (name_isakmp_nptype[i].key == k)
328 			return name_isakmp_nptype[i].str;
329 	return num2str(k);
330 }
331 
332 #ifdef ENABLE_HYBRID
333 /* isakmp_cfg.h / isakmp_unity.h / isakmp_xauth.h */
334 static struct ksmap name_isakmp_cfg_type[] = {
335 { INTERNAL_IP4_ADDRESS,		"INTERNAL_IP4_ADDRESS",		NULL },
336 { INTERNAL_IP4_NETMASK,		"INTERNAL_IP4_NETMASK",		NULL },
337 { INTERNAL_IP4_DNS,		"INTERNAL_IP4_DNS",		NULL },
338 { INTERNAL_IP4_NBNS,		"INTERNAL_IP4_NBNS",		NULL },
339 { INTERNAL_ADDRESS_EXPIRY,	"INTERNAL_ADDRESS_EXPIRY",	NULL },
340 { INTERNAL_IP4_DHCP,		"INTERNAL_IP4_DHCP",		NULL },
341 { APPLICATION_VERSION,		"APPLICATION_VERSION",		NULL },
342 { INTERNAL_IP6_ADDRESS,		"INTERNAL_IP6_ADDRESS",		NULL },
343 { INTERNAL_IP6_NETMASK,		"INTERNAL_IP6_NETMASK",		NULL },
344 { INTERNAL_IP6_DNS,		"INTERNAL_IP6_DNS",		NULL },
345 { INTERNAL_IP6_NBNS,		"INTERNAL_IP6_NBNS",		NULL },
346 { INTERNAL_IP6_DHCP,		"INTERNAL_IP6_DHCP",		NULL },
347 { INTERNAL_IP4_SUBNET,		"INTERNAL_IP4_SUBNET",		NULL },
348 { SUPPORTED_ATTRIBUTES,		"SUPPORTED_ATTRIBUTES",		NULL },
349 { INTERNAL_IP6_SUBNET,		"INTERNAL_IP6_SUBNET",		NULL },
350 { XAUTH_TYPE,			"XAUTH_TYPE",			NULL },
351 { XAUTH_USER_NAME,		"XAUTH_USER_NAME",		NULL },
352 { XAUTH_USER_PASSWORD,		"XAUTH_USER_PASSWORD",		NULL },
353 { XAUTH_PASSCODE,		"XAUTH_PASSCODE",		NULL },
354 { XAUTH_MESSAGE,		"XAUTH_MESSAGE",		NULL },
355 { XAUTH_CHALLENGE,		"XAUTH_CHALLENGE",		NULL },
356 { XAUTH_DOMAIN,			"XAUTH_DOMAIN",			NULL },
357 { XAUTH_STATUS,			"XAUTH_STATUS",			NULL },
358 { XAUTH_NEXT_PIN,		"XAUTH_NEXT_PIN",		NULL },
359 { XAUTH_ANSWER,			"XAUTH_ANSWER",			NULL },
360 { UNITY_BANNER,			"UNITY_BANNER",			NULL },
361 { UNITY_SAVE_PASSWD,		"UNITY_SAVE_PASSWD",		NULL },
362 { UNITY_DEF_DOMAIN,		"UNITY_DEF_DOMAIN",		NULL },
363 { UNITY_SPLITDNS_NAME,		"UNITY_SPLITDNS_NAME",		NULL },
364 { UNITY_SPLIT_INCLUDE,		"UNITY_SPLIT_INCLUDE",		NULL },
365 { UNITY_NATT_PORT,		"UNITY_NATT_PORT",		NULL },
366 { UNITY_LOCAL_LAN,		"UNITY_LOCAL_LAN",		NULL },
367 { UNITY_PFS,			"UNITY_PFS",			NULL },
368 { UNITY_FW_TYPE,		"UNITY_FW_TYPE",		NULL },
369 { UNITY_BACKUP_SERVERS,		"UNITY_BACKUP_SERVERS",		NULL },
370 { UNITY_DDNS_HOSTNAME,		"UNITY_DDNS_HOSTNAME",		NULL },
371 };
372 
373 char *
s_isakmp_cfg_type(k)374 s_isakmp_cfg_type(k)
375 	int k;
376 {
377 	int i;
378 	for (i = 0; i < ARRAYLEN(name_isakmp_cfg_type); i++)
379 		if (name_isakmp_cfg_type[i].key == k)
380 			return name_isakmp_cfg_type[i].str;
381 	return num2str(k);
382 }
383 
384 /* isakmp_cfg.h / isakmp_unity.h / isakmp_xauth.h */
385 static struct ksmap name_isakmp_cfg_ptype[] = {
386 { ISAKMP_CFG_ACK,		"mode config ACK",		NULL },
387 { ISAKMP_CFG_SET,		"mode config SET",		NULL },
388 { ISAKMP_CFG_REQUEST,		"mode config REQUEST",		NULL },
389 { ISAKMP_CFG_REPLY,		"mode config REPLY",		NULL },
390 };
391 
392 char *
s_isakmp_cfg_ptype(k)393 s_isakmp_cfg_ptype(k)
394 	int k;
395 {
396 	int i;
397 	for (i = 0; i < ARRAYLEN(name_isakmp_cfg_ptype); i++)
398 		if (name_isakmp_cfg_ptype[i].key == k)
399 			return name_isakmp_cfg_ptype[i].str;
400 	return num2str(k);
401 }
402 
403 #endif
404 
405 /* ipsec_doi.h */
406 static struct ksmap name_ipsecdoi_proto[] = {
407 { IPSECDOI_PROTO_ISAKMP,	"ISAKMP",	s_ipsecdoi_trns_isakmp },
408 { IPSECDOI_PROTO_IPSEC_AH,	"AH",		s_ipsecdoi_trns_ah },
409 { IPSECDOI_PROTO_IPSEC_ESP,	"ESP",		s_ipsecdoi_trns_esp },
410 { IPSECDOI_PROTO_IPCOMP,	"IPCOMP",	s_ipsecdoi_trns_ipcomp },
411 };
412 
413 char *
s_ipsecdoi_proto(k)414 s_ipsecdoi_proto(k)
415 	int k;
416 {
417 	int i;
418 	for (i = 0; i < ARRAYLEN(name_ipsecdoi_proto); i++)
419 		if (name_ipsecdoi_proto[i].key == k)
420 			return name_ipsecdoi_proto[i].str;
421 	return num2str(k);
422 }
423 
424 static struct ksmap name_ipsecdoi_trns_isakmp[] = {
425 { IPSECDOI_KEY_IKE,	"IKE", NULL },
426 };
427 
428 char *
s_ipsecdoi_trns_isakmp(k)429 s_ipsecdoi_trns_isakmp(k)
430 	int k;
431 {
432 	int i;
433 	for (i = 0; i < ARRAYLEN(name_ipsecdoi_trns_isakmp); i++)
434 		if (name_ipsecdoi_trns_isakmp[i].key == k)
435 			return name_ipsecdoi_trns_isakmp[i].str;
436 	return num2str(k);
437 }
438 
439 static struct ksmap name_ipsecdoi_trns_ah[] = {
440 { IPSECDOI_AH_MD5,	"MD5", NULL },
441 { IPSECDOI_AH_SHA,	"SHA", NULL },
442 { IPSECDOI_AH_DES,	"DES", NULL },
443 { IPSECDOI_AH_SHA256,	"SHA256", NULL },
444 { IPSECDOI_AH_SHA384,	"SHA384", NULL },
445 { IPSECDOI_AH_SHA512,	"SHA512", NULL },
446 };
447 
448 char *
s_ipsecdoi_trns_ah(k)449 s_ipsecdoi_trns_ah(k)
450 	int k;
451 {
452 	int i;
453 	for (i = 0; i < ARRAYLEN(name_ipsecdoi_trns_ah); i++)
454 		if (name_ipsecdoi_trns_ah[i].key == k)
455 			return name_ipsecdoi_trns_ah[i].str;
456 	return num2str(k);
457 }
458 
459 static struct ksmap name_ipsecdoi_trns_esp[] = {
460 { IPSECDOI_ESP_DES_IV64,	"DES_IV64",	NULL },
461 { IPSECDOI_ESP_DES,		"DES",		NULL },
462 { IPSECDOI_ESP_3DES,		"3DES",		NULL },
463 { IPSECDOI_ESP_RC5,		"RC5",		NULL },
464 { IPSECDOI_ESP_IDEA,		"IDEA",		NULL },
465 { IPSECDOI_ESP_CAST,		"CAST",		NULL },
466 { IPSECDOI_ESP_BLOWFISH,	"BLOWFISH",	NULL },
467 { IPSECDOI_ESP_3IDEA,		"3IDEA",	NULL },
468 { IPSECDOI_ESP_DES_IV32,	"DES_IV32",	NULL },
469 { IPSECDOI_ESP_RC4,		"RC4",		NULL },
470 { IPSECDOI_ESP_NULL,		"NULL",		NULL },
471 { IPSECDOI_ESP_AES,		"AES",		NULL },
472 { IPSECDOI_ESP_TWOFISH,		"TWOFISH",	NULL },
473 { IPSECDOI_ESP_CAMELLIA,	"CAMELLIA",	NULL },
474 };
475 
476 char *
s_ipsecdoi_trns_esp(k)477 s_ipsecdoi_trns_esp(k)
478 	int k;
479 {
480 	int i;
481 	for (i = 0; i < ARRAYLEN(name_ipsecdoi_trns_esp); i++)
482 		if (name_ipsecdoi_trns_esp[i].key == k)
483 			return name_ipsecdoi_trns_esp[i].str;
484 	return num2str(k);
485 }
486 
487 static struct ksmap name_ipsecdoi_trns_ipcomp[] = {
488 { IPSECDOI_IPCOMP_OUI,		"OUI",		NULL},
489 { IPSECDOI_IPCOMP_DEFLATE,	"DEFLATE",	NULL},
490 { IPSECDOI_IPCOMP_LZS,		"LZS",		NULL},
491 };
492 
493 char *
s_ipsecdoi_trns_ipcomp(k)494 s_ipsecdoi_trns_ipcomp(k)
495 	int k;
496 {
497 	int i;
498 	for (i = 0; i < ARRAYLEN(name_ipsecdoi_trns_ipcomp); i++)
499 		if (name_ipsecdoi_trns_ipcomp[i].key == k)
500 			return name_ipsecdoi_trns_ipcomp[i].str;
501 	return num2str(k);
502 }
503 
504 char *
s_ipsecdoi_trns(proto,trns)505 s_ipsecdoi_trns(proto, trns)
506 	int proto, trns;
507 {
508 	int i;
509 	for (i = 0; i < ARRAYLEN(name_ipsecdoi_proto); i++)
510 		if (name_ipsecdoi_proto[i].key == proto
511 		 && name_ipsecdoi_proto[i].f)
512 			return (name_ipsecdoi_proto[i].f)(trns);
513 	return num2str(trns);
514 }
515 
516 static struct ksmap name_attr_ipsec[] = {
517 { IPSECDOI_ATTR_SA_LD_TYPE,	"SA Life Type",		s_ipsecdoi_ltype },
518 { IPSECDOI_ATTR_SA_LD,		"SA Life Duration",	NULL },
519 { IPSECDOI_ATTR_GRP_DESC,	"Group Description",	NULL },
520 { IPSECDOI_ATTR_ENC_MODE,	"Encryption Mode",	s_ipsecdoi_encmode },
521 { IPSECDOI_ATTR_AUTH,		"Authentication Algorithm", s_ipsecdoi_auth },
522 { IPSECDOI_ATTR_KEY_LENGTH,	"Key Length",		NULL },
523 { IPSECDOI_ATTR_KEY_ROUNDS,	"Key Rounds",		NULL },
524 { IPSECDOI_ATTR_COMP_DICT_SIZE,	"Compression Dictionary Size",	NULL },
525 { IPSECDOI_ATTR_COMP_PRIVALG,	"Compression Private Algorithm", NULL },
526 };
527 
528 char *
s_ipsecdoi_attr(k)529 s_ipsecdoi_attr(k)
530 	int k;
531 {
532 	int i;
533 	for (i = 0; i < ARRAYLEN(name_attr_ipsec); i++)
534 		if (name_attr_ipsec[i].key == k)
535 			return name_attr_ipsec[i].str;
536 	return num2str(k);
537 }
538 
539 static struct ksmap name_attr_ipsec_ltype[] = {
540 { IPSECDOI_ATTR_SA_LD_TYPE_SEC,	"seconds",	NULL },
541 { IPSECDOI_ATTR_SA_LD_TYPE_KB,	"kilobytes",	NULL },
542 };
543 
544 char *
s_ipsecdoi_ltype(k)545 s_ipsecdoi_ltype(k)
546 	int k;
547 {
548 	int i;
549 	for (i = 0; i < ARRAYLEN(name_attr_ipsec_ltype); i++)
550 		if (name_attr_ipsec_ltype[i].key == k)
551 			return name_attr_ipsec_ltype[i].str;
552 	return num2str(k);
553 }
554 
555 static struct ksmap name_attr_ipsec_encmode[] = {
556 { IPSECDOI_ATTR_ENC_MODE_ANY,		"Any",		NULL },
557 { IPSECDOI_ATTR_ENC_MODE_TUNNEL,	"Tunnel",	NULL },
558 { IPSECDOI_ATTR_ENC_MODE_TRNS,		"Transport",	NULL },
559 { IPSECDOI_ATTR_ENC_MODE_UDPTUNNEL_RFC,	"UDP-Tunnel",	NULL },
560 { IPSECDOI_ATTR_ENC_MODE_UDPTRNS_RFC,	"UDP-Transport",	NULL },
561 { IPSECDOI_ATTR_ENC_MODE_UDPTUNNEL_DRAFT,	"UDP-Tunnel",	NULL },
562 { IPSECDOI_ATTR_ENC_MODE_UDPTRNS_DRAFT,	"UDP-Transport",	NULL },
563 };
564 
565 char *
s_ipsecdoi_encmode(k)566 s_ipsecdoi_encmode(k)
567 	int k;
568 {
569 	int i;
570 	for (i = 0; i < ARRAYLEN(name_attr_ipsec_encmode); i++)
571 		if (name_attr_ipsec_encmode[i].key == k)
572 			return name_attr_ipsec_encmode[i].str;
573 	return num2str(k);
574 }
575 
576 static struct ksmap name_attr_ipsec_auth[] = {
577 { IPSECDOI_ATTR_AUTH_HMAC_MD5,		"hmac-md5",	NULL },
578 { IPSECDOI_ATTR_AUTH_HMAC_SHA1,		"hmac-sha",	NULL },
579 { IPSECDOI_ATTR_AUTH_HMAC_SHA2_256,	"hmac-sha256",	NULL },
580 { IPSECDOI_ATTR_AUTH_HMAC_SHA2_384,	"hmac-sha384",	NULL },
581 { IPSECDOI_ATTR_AUTH_HMAC_SHA2_512,	"hmac-sha512",	NULL },
582 { IPSECDOI_ATTR_AUTH_DES_MAC,		"des-mac",	NULL },
583 { IPSECDOI_ATTR_AUTH_KPDK,		"kpdk",		NULL },
584 };
585 
586 char *
s_ipsecdoi_auth(k)587 s_ipsecdoi_auth(k)
588 	int k;
589 {
590 	int i;
591 	for (i = 0; i < ARRAYLEN(name_attr_ipsec_auth); i++)
592 		if (name_attr_ipsec_auth[i].key == k)
593 			return name_attr_ipsec_auth[i].str;
594 	return num2str(k);
595 }
596 
597 char *
s_ipsecdoi_attr_v(type,val)598 s_ipsecdoi_attr_v(type, val)
599 	int type, val;
600 {
601 	int i;
602 	for (i = 0; i < ARRAYLEN(name_attr_ipsec); i++)
603 		if (name_attr_ipsec[i].key == type
604 		 && name_attr_ipsec[i].f)
605 			return (name_attr_ipsec[i].f)(val);
606 	return num2str(val);
607 }
608 
609 static struct ksmap name_ipsecdoi_ident[] = {
610 { IPSECDOI_ID_IPV4_ADDR,	"IPv4_address",	NULL },
611 { IPSECDOI_ID_FQDN,		"FQDN",		NULL },
612 { IPSECDOI_ID_USER_FQDN,	"User_FQDN",	NULL },
613 { IPSECDOI_ID_IPV4_ADDR_SUBNET,	"IPv4_subnet",	NULL },
614 { IPSECDOI_ID_IPV6_ADDR,	"IPv6_address",	NULL },
615 { IPSECDOI_ID_IPV6_ADDR_SUBNET,	"IPv6_subnet",	NULL },
616 { IPSECDOI_ID_IPV4_ADDR_RANGE,	"IPv4_address_range",	NULL },
617 { IPSECDOI_ID_IPV6_ADDR_RANGE,	"IPv6_address_range",	NULL },
618 { IPSECDOI_ID_DER_ASN1_DN,	"DER_ASN1_DN",	NULL },
619 { IPSECDOI_ID_DER_ASN1_GN,	"DER_ASN1_GN",	NULL },
620 { IPSECDOI_ID_KEY_ID,		"KEY_ID",	NULL },
621 };
622 
623 char *
s_ipsecdoi_ident(k)624 s_ipsecdoi_ident(k)
625 	int k;
626 {
627 	int i;
628 	for (i = 0; i < ARRAYLEN(name_ipsecdoi_ident); i++)
629 		if (name_ipsecdoi_ident[i].key == k)
630 			return name_ipsecdoi_ident[i].str;
631 	return num2str(k);
632 }
633 
634 /* oakley.h */
635 static struct ksmap name_oakley_attr[] = {
636 { OAKLEY_ATTR_ENC_ALG,		"Encryption Algorithm",	s_attr_isakmp_enc },
637 { OAKLEY_ATTR_HASH_ALG,		"Hash Algorithm",	s_attr_isakmp_hash },
638 { OAKLEY_ATTR_AUTH_METHOD,	"Authentication Method", s_oakley_attr_method },
639 { OAKLEY_ATTR_GRP_DESC,		"Group Description",	s_attr_isakmp_desc },
640 { OAKLEY_ATTR_GRP_TYPE,		"Group Type",		s_attr_isakmp_group },
641 { OAKLEY_ATTR_GRP_PI,		"Group Prime/Irreducible Polynomial",	NULL },
642 { OAKLEY_ATTR_GRP_GEN_ONE,	"Group Generator One",	NULL },
643 { OAKLEY_ATTR_GRP_GEN_TWO,	"Group Generator Two",	NULL },
644 { OAKLEY_ATTR_GRP_CURVE_A,	"Group Curve A",	NULL },
645 { OAKLEY_ATTR_GRP_CURVE_B,	"Group Curve B",	NULL },
646 { OAKLEY_ATTR_SA_LD_TYPE,	"Life Type",		s_attr_isakmp_ltype },
647 { OAKLEY_ATTR_SA_LD,		"Life Duration",	NULL },
648 { OAKLEY_ATTR_PRF,		"PRF",			NULL },
649 { OAKLEY_ATTR_KEY_LEN,		"Key Length",		NULL },
650 { OAKLEY_ATTR_FIELD_SIZE,	"Field Size",		NULL },
651 { OAKLEY_ATTR_GRP_ORDER,	"Group Order",		NULL },
652 { OAKLEY_ATTR_BLOCK_SIZE,	"Block Size",		NULL },
653 { OAKLEY_ATTR_GSS_ID,		"GSS-API endpoint name",NULL },
654 };
655 
656 char *
s_oakley_attr(k)657 s_oakley_attr(k)
658 	int k;
659 {
660 	int i;
661 	for (i = 0; i < ARRAYLEN(name_oakley_attr); i++)
662 		if (name_oakley_attr[i].key == k)
663 			return name_oakley_attr[i].str;
664 	return num2str(k);
665 }
666 
667 static struct ksmap name_attr_isakmp_enc[] = {
668 { OAKLEY_ATTR_ENC_ALG_DES,	"DES-CBC",		NULL },
669 { OAKLEY_ATTR_ENC_ALG_IDEA,	"IDEA-CBC",		NULL },
670 { OAKLEY_ATTR_ENC_ALG_BLOWFISH,	"Blowfish-CBC",		NULL },
671 { OAKLEY_ATTR_ENC_ALG_RC5,	"RC5-R16-B64-CBC",	NULL },
672 { OAKLEY_ATTR_ENC_ALG_3DES,	"3DES-CBC",		NULL },
673 { OAKLEY_ATTR_ENC_ALG_CAST,	"CAST-CBC",		NULL },
674 { OAKLEY_ATTR_ENC_ALG_AES,	"AES-CBC",		NULL },
675 };
676 
677 char *
s_attr_isakmp_enc(k)678 s_attr_isakmp_enc(k)
679 	int k;
680 {
681 	int i;
682 	for (i = 0; i < ARRAYLEN(name_attr_isakmp_enc); i++)
683 		if (name_attr_isakmp_enc[i].key == k)
684 			return name_attr_isakmp_enc[i].str;
685 	return num2str(k);
686 }
687 
688 static struct ksmap name_attr_isakmp_hash[] = {
689 { OAKLEY_ATTR_HASH_ALG_MD5,	"MD5",		NULL },
690 { OAKLEY_ATTR_HASH_ALG_SHA,	"SHA",		NULL },
691 { OAKLEY_ATTR_HASH_ALG_TIGER,	"Tiger",	NULL },
692 { OAKLEY_ATTR_HASH_ALG_SHA2_256,"SHA256",	NULL },
693 { OAKLEY_ATTR_HASH_ALG_SHA2_384,"SHA384",	NULL },
694 { OAKLEY_ATTR_HASH_ALG_SHA2_512,"SHA512",	NULL },
695 };
696 
697 char *
s_attr_isakmp_hash(k)698 s_attr_isakmp_hash(k)
699 	int k;
700 {
701 	int i;
702 	for (i = 0; i < ARRAYLEN(name_attr_isakmp_hash); i++)
703 		if (name_attr_isakmp_hash[i].key == k)
704 			return name_attr_isakmp_hash[i].str;
705 	return num2str(k);
706 }
707 
708 static struct ksmap name_attr_isakmp_method[] = {
709 { OAKLEY_ATTR_AUTH_METHOD_PSKEY,		"pre-shared key",	NULL },
710 { OAKLEY_ATTR_AUTH_METHOD_DSSSIG,		"DSS signatures",	NULL },
711 { OAKLEY_ATTR_AUTH_METHOD_RSASIG,		"RSA signatures",	NULL },
712 { OAKLEY_ATTR_AUTH_METHOD_RSAENC,		"Encryption with RSA",	NULL },
713 { OAKLEY_ATTR_AUTH_METHOD_RSAREV,		"Revised encryption with RSA",	NULL },
714 { OAKLEY_ATTR_AUTH_METHOD_EGENC,		"Encryption with El-Gamal",	NULL },
715 { OAKLEY_ATTR_AUTH_METHOD_EGREV,		"Revised encryption with El-Gamal",	NULL },
716 #ifdef HAVE_GSSAPI
717 { OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB,		"GSS-API on Kerberos 5", NULL },
718 #endif
719 #ifdef ENABLE_HYBRID
720 { OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_R,		"Hybrid DSS server",	NULL },
721 { OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_R,		"Hybrid RSA server",	NULL },
722 { OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_I,		"Hybrid DSS client",	NULL },
723 { OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I,		"Hybrid RSA client",	NULL },
724 { OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_I,	"XAuth pskey client",	NULL },
725 { OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R,	"XAuth pskey server",	NULL },
726 { OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I,	"XAuth RSASIG client",	NULL },
727 { OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_R,	"XAuth RSASIG server",	NULL },
728 #endif
729 };
730 
731 char *
s_oakley_attr_method(k)732 s_oakley_attr_method(k)
733 	int k;
734 {
735 	int i;
736 	for (i = 0; i < ARRAYLEN(name_attr_isakmp_method); i++)
737 		if (name_attr_isakmp_method[i].key == k)
738 			return name_attr_isakmp_method[i].str;
739 	return num2str(k);
740 }
741 
742 static struct ksmap name_attr_isakmp_desc[] = {
743 { OAKLEY_ATTR_GRP_DESC_MODP768,		"768-bit MODP group",	NULL },
744 { OAKLEY_ATTR_GRP_DESC_MODP1024,	"1024-bit MODP group",	NULL },
745 { OAKLEY_ATTR_GRP_DESC_EC2N155,		"EC2N group on GP[2^155]",	NULL },
746 { OAKLEY_ATTR_GRP_DESC_EC2N185,		"EC2N group on GP[2^185]",	NULL },
747 { OAKLEY_ATTR_GRP_DESC_MODP1536,	"1536-bit MODP group",	NULL },
748 { OAKLEY_ATTR_GRP_DESC_MODP2048,	"2048-bit MODP group",	NULL },
749 { OAKLEY_ATTR_GRP_DESC_MODP3072,	"3072-bit MODP group",	NULL },
750 { OAKLEY_ATTR_GRP_DESC_MODP4096,	"4096-bit MODP group",	NULL },
751 { OAKLEY_ATTR_GRP_DESC_MODP6144,	"6144-bit MODP group",	NULL },
752 { OAKLEY_ATTR_GRP_DESC_MODP8192,	"8192-bit MODP group",	NULL },
753 };
754 
755 char *
s_attr_isakmp_desc(k)756 s_attr_isakmp_desc(k)
757 	int k;
758 {
759 	int i;
760 	for (i = 0; i < ARRAYLEN(name_attr_isakmp_desc); i++)
761 		if (name_attr_isakmp_desc[i].key == k)
762 			return name_attr_isakmp_desc[i].str;
763 	return num2str(k);
764 }
765 
766 static struct ksmap name_attr_isakmp_group[] = {
767 { OAKLEY_ATTR_GRP_TYPE_MODP,	"MODP",	NULL },
768 { OAKLEY_ATTR_GRP_TYPE_ECP,	"ECP",	NULL },
769 { OAKLEY_ATTR_GRP_TYPE_EC2N,	"EC2N",	NULL },
770 };
771 
772 char *
s_attr_isakmp_group(k)773 s_attr_isakmp_group(k)
774 	int k;
775 {
776 	int i;
777 	for (i = 0; i < ARRAYLEN(name_attr_isakmp_group); i++)
778 		if (name_attr_isakmp_group[i].key == k)
779 			return name_attr_isakmp_group[i].str;
780 	return num2str(k);
781 }
782 
783 static struct ksmap name_attr_isakmp_ltype[] = {
784 { OAKLEY_ATTR_SA_LD_TYPE_SEC,	"seconds",	NULL },
785 { OAKLEY_ATTR_SA_LD_TYPE_KB,	"kilobytes",	NULL },
786 };
787 
788 char *
s_attr_isakmp_ltype(k)789 s_attr_isakmp_ltype(k)
790 	int k;
791 {
792 	int i;
793 	for (i = 0; i < ARRAYLEN(name_attr_isakmp_ltype); i++)
794 		if (name_attr_isakmp_ltype[i].key == k)
795 			return name_attr_isakmp_ltype[i].str;
796 	return num2str(k);
797 }
798 
799 char *
s_oakley_attr_v(type,val)800 s_oakley_attr_v(type, val)
801 	int type, val;
802 {
803 	int i;
804 	for (i = 0; i < ARRAYLEN(name_oakley_attr); i++)
805 		if (name_oakley_attr[i].key == type
806 		 && name_oakley_attr[i].f)
807 			return (name_oakley_attr[i].f)(val);
808 	return num2str(val);
809 }
810 
811 /* netinet6/ipsec.h */
812 static struct ksmap name_ipsec_level[] = {
813 { IPSEC_LEVEL_USE,	"use",		NULL },
814 { IPSEC_LEVEL_REQUIRE,	"require",	NULL },
815 { IPSEC_LEVEL_UNIQUE,	"unique",	NULL },
816 };
817 
818 char *
s_ipsec_level(k)819 s_ipsec_level(k)
820 	int k;
821 {
822 	int i;
823 	for (i = 0; i < ARRAYLEN(name_ipsec_level); i++)
824 		if (name_ipsec_level[i].key == k)
825 			return name_ipsec_level[i].str;
826 	return num2str(k);
827 }
828 
829 static struct ksmap name_algclass[] = {
830 { algclass_ipsec_enc,	"ipsec enc",	s_ipsecdoi_trns_esp },
831 { algclass_ipsec_auth,	"ipsec auth",	s_ipsecdoi_trns_ah },
832 { algclass_ipsec_comp,	"ipsec comp",	s_ipsecdoi_trns_ipcomp },
833 { algclass_isakmp_enc,	"isakmp enc",	s_attr_isakmp_enc },
834 { algclass_isakmp_hash,	"isakmp hash",	s_attr_isakmp_hash },
835 { algclass_isakmp_dh,	"isakmp dh",	s_attr_isakmp_desc },
836 { algclass_isakmp_ameth, "isakmp auth method",	s_oakley_attr_method },
837 };
838 
839 char *
s_algclass(k)840 s_algclass(k)
841 	int k;
842 {
843 	int i;
844 	for (i = 0; i < ARRAYLEN(name_algclass); i++)
845 		if (name_algclass[i].key == k)
846 			return name_algclass[i].str;
847 	return num2str(k);
848 }
849 
850 char *
s_algtype(class,n)851 s_algtype(class, n)
852 	int class, n;
853 {
854 	int i;
855 	for (i = 0; i < ARRAYLEN(name_algclass); i++)
856 		if (name_algclass[i].key == class
857 		 && name_algclass[i].f)
858 			return (name_algclass[i].f)(n);
859 	return num2str(n);
860 }
861 
862 /* pfkey.h */
863 static struct ksmap name_pfkey_type[] = {
864 { SADB_GETSPI,		"GETSPI",	NULL },
865 { SADB_UPDATE,		"UPDATE",	NULL },
866 { SADB_ADD,		"ADD",		NULL },
867 { SADB_DELETE,		"DELETE",	NULL },
868 { SADB_GET,		"GET",		NULL },
869 { SADB_ACQUIRE,		"ACQUIRE",	NULL },
870 { SADB_REGISTER,	"REGISTER",	NULL },
871 { SADB_EXPIRE,		"EXPIRE",	NULL },
872 { SADB_FLUSH,		"FLUSH",	NULL },
873 { SADB_DUMP,		"DUMP",		NULL },
874 { SADB_X_PROMISC,	"X_PROMISC",	NULL },
875 { SADB_X_PCHANGE,	"X_PCHANGE",	NULL },
876 { SADB_X_SPDUPDATE,	"X_SPDUPDATE",	NULL },
877 { SADB_X_SPDADD,	"X_SPDADD",	NULL },
878 { SADB_X_SPDDELETE,	"X_SPDDELETE",	NULL },
879 { SADB_X_SPDGET,	"X_SPDGET",	NULL },
880 { SADB_X_SPDACQUIRE,	"X_SPDACQUIRE",	NULL },
881 { SADB_X_SPDDUMP,	"X_SPDDUMP",	NULL },
882 { SADB_X_SPDFLUSH,	"X_SPDFLUSH",	NULL },
883 { SADB_X_SPDSETIDX,	"X_SPDSETIDX",	NULL },
884 { SADB_X_SPDEXPIRE,	"X_SPDEXPIRE",	NULL },
885 { SADB_X_SPDDELETE2,	"X_SPDDELETE2",	NULL },
886 #ifdef SADB_X_NAT_T_NEW_MAPPING
887 { SADB_X_NAT_T_NEW_MAPPING, "X_NAT_T_NEW_MAPPING", NULL },
888 #endif
889 #ifdef SADB_X_MIGRATE
890 { SADB_X_MIGRATE,	"X_MIGRATE",	NULL },
891 #endif
892 };
893 
894 char *
s_pfkey_type(k)895 s_pfkey_type(k)
896 	int k;
897 {
898 	int i;
899 	for (i = 0; i < ARRAYLEN(name_pfkey_type); i++)
900 		if (name_pfkey_type[i].key == k)
901 			return name_pfkey_type[i].str;
902 	return num2str(k);
903 }
904 
905 static struct ksmap name_pfkey_satype[] = {
906 { SADB_SATYPE_UNSPEC,	"UNSPEC",	NULL },
907 { SADB_SATYPE_AH,	"AH",		NULL },
908 { SADB_SATYPE_ESP,	"ESP",		NULL },
909 { SADB_SATYPE_RSVP,	"RSVP",		NULL },
910 { SADB_SATYPE_OSPFV2,	"OSPFV2",	NULL },
911 { SADB_SATYPE_RIPV2,	"RIPV2",	NULL },
912 { SADB_SATYPE_MIP,	"MIP",		NULL },
913 { SADB_X_SATYPE_IPCOMP,	"IPCOMP",	NULL },
914 };
915 
916 char *
s_pfkey_satype(k)917 s_pfkey_satype(k)
918 	int k;
919 {
920 	int i;
921 	for (i = 0; i < ARRAYLEN(name_pfkey_satype); i++)
922 		if (name_pfkey_satype[i].key == k)
923 			return name_pfkey_satype[i].str;
924 	return num2str(k);
925 }
926 
927 static struct ksmap name_direction[] = {
928 { IPSEC_DIR_INBOUND,	"in",	NULL },
929 { IPSEC_DIR_OUTBOUND,	"out",	NULL },
930 #ifdef HAVE_POLICY_FWD
931 { IPSEC_DIR_FWD,	"fwd",	NULL },
932 #endif
933 };
934 
935 char *
s_direction(k)936 s_direction(k)
937 	int k;
938 {
939 	int i;
940 	for (i = 0; i < ARRAYLEN(name_direction); i++)
941 		if (name_direction[i].key == k)
942 			return name_direction[i].str;
943 	return num2str(k);
944 }
945 
946 char *
s_proto(k)947 s_proto(k)
948 	int k;
949 {
950 	switch (k) {
951 	case IPPROTO_ICMP:
952 		return "icmp";
953 	case IPPROTO_TCP:
954 		return "tcp";
955 	case IPPROTO_UDP:
956 		return "udp";
957 	case IPPROTO_ICMPV6:
958 		return "icmpv6";
959 	case IPSEC_ULPROTO_ANY:
960 		return "any";
961 	}
962 
963 	return num2str(k);
964 }
965 
966 char *
s_doi(int k)967 s_doi(int k)
968 {
969   switch (k) {
970     case IPSEC_DOI:
971       return "ipsec_doi";
972     default:
973       return num2str(k);
974   }
975 }
976 
977 char *
s_etype(int k)978 s_etype (int k)
979 {
980   switch (k) {
981     case ISAKMP_ETYPE_NONE:
982       return "_none";
983     case ISAKMP_ETYPE_BASE:
984       return "base";
985     case ISAKMP_ETYPE_IDENT:
986       return "main";
987     case ISAKMP_ETYPE_AUTH:
988       return "_auth";
989     case ISAKMP_ETYPE_AGG:
990       return "aggressive";
991     case ISAKMP_ETYPE_INFO:
992       return "_info";
993     case ISAKMP_ETYPE_QUICK:
994       return "_quick";
995     case ISAKMP_ETYPE_NEWGRP:
996       return "_newgrp";
997     case ISAKMP_ETYPE_ACKINFO:
998       return "_ackinfo";
999     default:
1000       return num2str(k);
1001   }
1002 }
1003 
1004 char *
s_idtype(int k)1005 s_idtype (int k)
1006 {
1007   switch (k) {
1008     case IDTYPE_FQDN:
1009       return "fqdn";
1010     case IDTYPE_USERFQDN:
1011       return "user_fqdn";
1012     case IDTYPE_KEYID:
1013       return "keyid";
1014     case IDTYPE_ADDRESS:
1015       return "address";
1016     case IDTYPE_ASN1DN:
1017       return "asn1dn";
1018     default:
1019       return num2str(k);
1020   }
1021 }
1022 
1023 char *
s_switch(int k)1024 s_switch (int k)
1025 {
1026   switch (k) {
1027     case FALSE:
1028       return "off";
1029     case TRUE:
1030       return "on";
1031     default:
1032       return num2str(k);
1033   }
1034 }
1035