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