]> git.saurik.com Git - apple/network_cmds.git/blob - racoon.tproj/strnames.c
network_cmds-176.tar.gz
[apple/network_cmds.git] / racoon.tproj / strnames.c
1 /* $KAME: strnames.c,v 1.23 2001/12/12 18:23:42 sakane 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 <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/socket.h>
35
36 #include <netinet6/ipsec.h>
37 #include <netinet/in.h>
38
39 #include <stdio.h>
40
41 #include "var.h"
42 #include "misc.h"
43 #include "vmbuf.h"
44
45 #include "isakmp_var.h"
46 #include "isakmp.h"
47 #include "ipsec_doi.h"
48 #include "oakley.h"
49 #include "handler.h"
50 #include "pfkey.h"
51 #include "strnames.h"
52 #include "algorithm.h"
53
54 struct ksmap {
55 int key;
56 char *str;
57 char *(*f) __P((int));
58 };
59
60 static char *num2str __P((int n));
61
62 static char *
63 num2str(n)
64 int n;
65 {
66 static char buf[20];
67
68 snprintf(buf, sizeof(buf), "%d", n);
69
70 return buf;
71 }
72
73 /* isakmp.h */
74 char *
75 s_isakmp_state(t, d, s)
76 int t, d, s;
77 {
78 switch (t) {
79 case ISAKMP_ETYPE_AGG:
80 switch (d) {
81 case INITIATOR:
82 switch (s) {
83 case PHASE1ST_MSG1SENT:
84 return "agg I msg1";
85 case PHASE1ST_ESTABLISHED:
86 return "agg I msg2";
87 default:
88 break;
89 }
90 case RESPONDER:
91 switch (s) {
92 case PHASE1ST_MSG1SENT:
93 return "agg R msg1";
94 default:
95 break;
96 }
97 }
98 break;
99 case ISAKMP_ETYPE_BASE:
100 switch (d) {
101 case INITIATOR:
102 switch (s) {
103 case PHASE1ST_MSG1SENT:
104 return "base I msg1";
105 case PHASE1ST_MSG2SENT:
106 return "base I msg2";
107 default:
108 break;
109 }
110 case RESPONDER:
111 switch (s) {
112 case PHASE1ST_MSG1SENT:
113 return "base R msg1";
114 case PHASE1ST_ESTABLISHED:
115 return "base R msg2";
116 default:
117 break;
118 }
119 }
120 break;
121 case ISAKMP_ETYPE_IDENT:
122 switch (d) {
123 case INITIATOR:
124 switch (s) {
125 case PHASE1ST_MSG1SENT:
126 return "ident I msg1";
127 case PHASE1ST_MSG2SENT:
128 return "ident I msg2";
129 case PHASE1ST_MSG3SENT:
130 return "ident I msg3";
131 default:
132 break;
133 }
134 case RESPONDER:
135 switch (s) {
136 case PHASE1ST_MSG1SENT:
137 return "ident R msg1";
138 case PHASE1ST_MSG2SENT:
139 return "ident R msg2";
140 case PHASE1ST_ESTABLISHED:
141 return "ident R msg3";
142 default:
143 break;
144 }
145 }
146 break;
147 case ISAKMP_ETYPE_QUICK:
148 switch (d) {
149 case INITIATOR:
150 switch (s) {
151 case PHASE2ST_MSG1SENT:
152 return "quick I msg1";
153 case PHASE2ST_ADDSA:
154 return "quick I msg2";
155 default:
156 break;
157 }
158 case RESPONDER:
159 switch (s) {
160 case PHASE2ST_MSG1SENT:
161 return "quick R msg1";
162 case PHASE2ST_COMMIT:
163 return "quick R msg2";
164 default:
165 break;
166 }
167 }
168 break;
169 default:
170 case ISAKMP_ETYPE_NONE:
171 case ISAKMP_ETYPE_AUTH:
172 case ISAKMP_ETYPE_INFO:
173 case ISAKMP_ETYPE_NEWGRP:
174 case ISAKMP_ETYPE_ACKINFO:
175 break;
176 }
177 /*NOTREACHED*/
178
179 return "???";
180 }
181
182 static struct ksmap name_isakmp_certtype[] = {
183 { ISAKMP_CERT_NONE, "NONE", NULL },
184 { ISAKMP_CERT_PKCS7, "PKCS #7 wrapped X.509 certificate", NULL },
185 { ISAKMP_CERT_PGP, "PGP Certificate", NULL },
186 { ISAKMP_CERT_DNS, "DNS Signed Key", NULL },
187 { ISAKMP_CERT_X509SIGN, "X.509 Certificate Signature", NULL },
188 { ISAKMP_CERT_X509KE, "X.509 Certificate Key Exchange", NULL },
189 { ISAKMP_CERT_KERBEROS, "Kerberos Tokens", NULL },
190 { ISAKMP_CERT_CRL, "Certificate Revocation List (CRL)", NULL },
191 { ISAKMP_CERT_ARL, "Authority Revocation List (ARL)", NULL },
192 { ISAKMP_CERT_SPKI, "SPKI Certificate", NULL },
193 { ISAKMP_CERT_X509ATTR, "X.509 Certificate Attribute", NULL },
194 };
195
196 char *
197 s_isakmp_certtype(k)
198 int k;
199 {
200 int i;
201 for (i = 0; i < ARRAYLEN(name_isakmp_certtype); i++)
202 if (name_isakmp_certtype[i].key == k)
203 return name_isakmp_certtype[i].str;
204 return num2str(k);
205 }
206
207 static struct ksmap name_isakmp_etype[] = {
208 { ISAKMP_ETYPE_NONE, "None", NULL },
209 { ISAKMP_ETYPE_BASE, "Base", NULL },
210 { ISAKMP_ETYPE_IDENT, "Identity Protection", NULL },
211 { ISAKMP_ETYPE_AUTH, "Authentication Only", NULL },
212 { ISAKMP_ETYPE_AGG, "Aggressive", NULL },
213 { ISAKMP_ETYPE_INFO, "Informational", NULL },
214 { ISAKMP_ETYPE_QUICK, "Quick", NULL },
215 { ISAKMP_ETYPE_NEWGRP, "New Group", NULL },
216 { ISAKMP_ETYPE_ACKINFO, "Acknowledged Informational", NULL },
217 };
218
219 char *
220 s_isakmp_etype(k)
221 int k;
222 {
223 int i;
224 for (i = 0; i < ARRAYLEN(name_isakmp_etype); i++)
225 if (name_isakmp_etype[i].key == k)
226 return name_isakmp_etype[i].str;
227 return num2str(k);
228 }
229
230 static struct ksmap name_isakmp_notify_msg[] = {
231 { ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE, "INVALID-PAYLOAD-TYPE", NULL },
232 { ISAKMP_NTYPE_DOI_NOT_SUPPORTED, "DOI-NOT-SUPPORTED", NULL },
233 { ISAKMP_NTYPE_SITUATION_NOT_SUPPORTED, "SITUATION-NOT-SUPPORTED", NULL },
234 { ISAKMP_NTYPE_INVALID_COOKIE, "INVALID-COOKIE", NULL },
235 { ISAKMP_NTYPE_INVALID_MAJOR_VERSION, "INVALID-MAJOR-VERSION", NULL },
236 { ISAKMP_NTYPE_INVALID_MINOR_VERSION, "INVALID-MINOR-VERSION", NULL },
237 { ISAKMP_NTYPE_INVALID_EXCHANGE_TYPE, "INVALID-EXCHANGE-TYPE", NULL },
238 { ISAKMP_NTYPE_INVALID_FLAGS, "INVALID-FLAGS", NULL },
239 { ISAKMP_NTYPE_INVALID_MESSAGE_ID, "INVALID-MESSAGE-ID", NULL },
240 { ISAKMP_NTYPE_INVALID_PROTOCOL_ID, "INVALID-PROTOCOL-ID", NULL },
241 { ISAKMP_NTYPE_INVALID_SPI, "INVALID-SPI", NULL },
242 { ISAKMP_NTYPE_INVALID_TRANSFORM_ID, "INVALID-TRANSFORM-ID", NULL },
243 { ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED, "ATTRIBUTES-NOT-SUPPORTED", NULL },
244 { ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN, "NO-PROPOSAL-CHOSEN", NULL },
245 { ISAKMP_NTYPE_BAD_PROPOSAL_SYNTAX, "BAD-PROPOSAL-SYNTAX", NULL },
246 { ISAKMP_NTYPE_PAYLOAD_MALFORMED, "PAYLOAD-MALFORMED", NULL },
247 { ISAKMP_NTYPE_INVALID_KEY_INFORMATION, "INVALID-KEY-INFORMATION", NULL },
248 { ISAKMP_NTYPE_INVALID_ID_INFORMATION, "INVALID-ID-INFORMATION", NULL },
249 { ISAKMP_NTYPE_INVALID_CERT_ENCODING, "INVALID-CERT-ENCODING", NULL },
250 { ISAKMP_NTYPE_INVALID_CERTIFICATE, "INVALID-CERTIFICATE", NULL },
251 { ISAKMP_NTYPE_BAD_CERT_REQUEST_SYNTAX, "BAD-CERT-REQUEST-SYNTAX", NULL },
252 { ISAKMP_NTYPE_INVALID_CERT_AUTHORITY, "INVALID-CERT-AUTHORITY", NULL },
253 { ISAKMP_NTYPE_INVALID_HASH_INFORMATION, "INVALID-HASH-INFORMATION", NULL },
254 { ISAKMP_NTYPE_AUTHENTICATION_FAILED, "AUTHENTICATION-FAILED", NULL },
255 { ISAKMP_NTYPE_INVALID_SIGNATURE, "INVALID-SIGNATURE", NULL },
256 { ISAKMP_NTYPE_ADDRESS_NOTIFICATION, "ADDRESS-NOTIFICATION", NULL },
257 { ISAKMP_NTYPE_NOTIFY_SA_LIFETIME, "NOTIFY-SA-LIFETIME", NULL },
258 { ISAKMP_NTYPE_CERTIFICATE_UNAVAILABLE, "CERTIFICATE-UNAVAILABLE", NULL },
259 { ISAKMP_NTYPE_UNSUPPORTED_EXCHANGE_TYPE, "UNSUPPORTED-EXCHANGE-TYPE", NULL },
260 { ISAKMP_NTYPE_UNEQUAL_PAYLOAD_LENGTHS, "UNEQUAL-PAYLOAD-LENGTHS", NULL },
261 { ISAKMP_NTYPE_CONNECTED, "CONNECTED", NULL },
262 { ISAKMP_NTYPE_RESPONDER_LIFETIME, "RESPONDER-LIFETIME", NULL },
263 { ISAKMP_NTYPE_REPLAY_STATUS, "REPLAY-STATUS", NULL },
264 { ISAKMP_NTYPE_INITIAL_CONTACT, "INITIAL-CONTACT", NULL },
265 { ISAKMP_LOG_RETRY_LIMIT_REACHED, "RETRY-LIMIT-REACHED", NULL },
266 };
267
268 char *
269 s_isakmp_notify_msg(k)
270 int k;
271 {
272 int i;
273 for (i = 0; i < ARRAYLEN(name_isakmp_notify_msg); i++)
274 if (name_isakmp_notify_msg[i].key == k)
275 return name_isakmp_notify_msg[i].str;
276
277 return num2str(k);
278 }
279
280 static struct ksmap name_isakmp_nptype[] = {
281 { ISAKMP_NPTYPE_NONE, "none", NULL },
282 { ISAKMP_NPTYPE_SA, "sa", NULL },
283 { ISAKMP_NPTYPE_P, "prop", NULL },
284 { ISAKMP_NPTYPE_T, "trns", NULL },
285 { ISAKMP_NPTYPE_KE, "ke", NULL },
286 { ISAKMP_NPTYPE_ID, "id", NULL },
287 { ISAKMP_NPTYPE_CERT, "cert", NULL },
288 { ISAKMP_NPTYPE_CR, "cr", NULL },
289 { ISAKMP_NPTYPE_HASH, "hash", NULL },
290 { ISAKMP_NPTYPE_SIG, "sig", NULL },
291 { ISAKMP_NPTYPE_NONCE, "nonce", NULL },
292 { ISAKMP_NPTYPE_N, "notify", NULL },
293 { ISAKMP_NPTYPE_D, "delete", NULL },
294 { ISAKMP_NPTYPE_VID, "vid", NULL },
295 { ISAKMP_NPTYPE_GSS, "gss id", NULL },
296 { 0, "", NULL },
297 { ISAKMP_NPTYPE_NATD, "natd", NULL }
298 };
299
300 char *
301 s_isakmp_nptype(k)
302 int k;
303 {
304 int i;
305 for (i = 0; i < ARRAYLEN(name_isakmp_nptype); i++)
306 if (name_isakmp_nptype[i].key == k)
307 return name_isakmp_nptype[i].str;
308 return num2str(k);
309 }
310
311 /* ipsec_doi.h */
312 static struct ksmap name_ipsecdoi_proto[] = {
313 { IPSECDOI_PROTO_ISAKMP, "ISAKMP", s_ipsecdoi_trns_isakmp },
314 { IPSECDOI_PROTO_IPSEC_AH, "AH", s_ipsecdoi_trns_ah },
315 { IPSECDOI_PROTO_IPSEC_ESP, "ESP", s_ipsecdoi_trns_esp },
316 { IPSECDOI_PROTO_IPCOMP, "IPCOMP", s_ipsecdoi_trns_ipcomp },
317 };
318
319 char *
320 s_ipsecdoi_proto(k)
321 int k;
322 {
323 int i;
324 for (i = 0; i < ARRAYLEN(name_ipsecdoi_proto); i++)
325 if (name_ipsecdoi_proto[i].key == k)
326 return name_ipsecdoi_proto[i].str;
327 return num2str(k);
328 }
329
330 static struct ksmap name_ipsecdoi_trns_isakmp[] = {
331 { IPSECDOI_KEY_IKE, "IKE", NULL },
332 };
333
334 char *
335 s_ipsecdoi_trns_isakmp(k)
336 int k;
337 {
338 int i;
339 for (i = 0; i < ARRAYLEN(name_ipsecdoi_trns_isakmp); i++)
340 if (name_ipsecdoi_trns_isakmp[i].key == k)
341 return name_ipsecdoi_trns_isakmp[i].str;
342 return num2str(k);
343 }
344
345 static struct ksmap name_ipsecdoi_trns_ah[] = {
346 { IPSECDOI_AH_MD5, "MD5", NULL },
347 { IPSECDOI_AH_SHA, "SHA", NULL },
348 { IPSECDOI_AH_DES, "DES", NULL },
349 };
350
351 char *
352 s_ipsecdoi_trns_ah(k)
353 int k;
354 {
355 int i;
356 for (i = 0; i < ARRAYLEN(name_ipsecdoi_trns_ah); i++)
357 if (name_ipsecdoi_trns_ah[i].key == k)
358 return name_ipsecdoi_trns_ah[i].str;
359 return num2str(k);
360 }
361
362 static struct ksmap name_ipsecdoi_trns_esp[] = {
363 { IPSECDOI_ESP_DES_IV64, "DES_IV64", NULL },
364 { IPSECDOI_ESP_DES, "DES", NULL },
365 { IPSECDOI_ESP_3DES, "3DES", NULL },
366 { IPSECDOI_ESP_RC5, "RC5", NULL },
367 { IPSECDOI_ESP_IDEA, "IDEA", NULL },
368 { IPSECDOI_ESP_CAST, "CAST", NULL },
369 { IPSECDOI_ESP_BLOWFISH, "BLOWFISH", NULL },
370 { IPSECDOI_ESP_3IDEA, "3IDEA", NULL },
371 { IPSECDOI_ESP_DES_IV32, "DES_IV32", NULL },
372 { IPSECDOI_ESP_RC4, "RC4", NULL },
373 { IPSECDOI_ESP_NULL, "NULL", NULL },
374 { IPSECDOI_ESP_RIJNDAEL, "RIJNDAEL", NULL },
375 { IPSECDOI_ESP_TWOFISH, "TWOFISH", NULL },
376 };
377
378 char *
379 s_ipsecdoi_trns_esp(k)
380 int k;
381 {
382 int i;
383 for (i = 0; i < ARRAYLEN(name_ipsecdoi_trns_esp); i++)
384 if (name_ipsecdoi_trns_esp[i].key == k)
385 return name_ipsecdoi_trns_esp[i].str;
386 return num2str(k);
387 }
388
389 static struct ksmap name_ipsecdoi_trns_ipcomp[] = {
390 { IPSECDOI_IPCOMP_OUI, "OUI", NULL},
391 { IPSECDOI_IPCOMP_DEFLATE, "DEFLATE", NULL},
392 { IPSECDOI_IPCOMP_LZS, "LZS", NULL},
393 };
394
395 char *
396 s_ipsecdoi_trns_ipcomp(k)
397 int k;
398 {
399 int i;
400 for (i = 0; i < ARRAYLEN(name_ipsecdoi_trns_ipcomp); i++)
401 if (name_ipsecdoi_trns_ipcomp[i].key == k)
402 return name_ipsecdoi_trns_ipcomp[i].str;
403 return num2str(k);
404 }
405
406 char *
407 s_ipsecdoi_trns(proto, trns)
408 int proto, trns;
409 {
410 int i;
411 for (i = 0; i < ARRAYLEN(name_ipsecdoi_proto); i++)
412 if (name_ipsecdoi_proto[i].key == proto
413 && name_ipsecdoi_proto[i].f)
414 return (name_ipsecdoi_proto[i].f)(trns);
415 return num2str(trns);
416 }
417
418 static struct ksmap name_attr_ipsec[] = {
419 { IPSECDOI_ATTR_SA_LD_TYPE, "SA Life Type", s_ipsecdoi_ltype },
420 { IPSECDOI_ATTR_SA_LD, "SA Life Duration", NULL },
421 { IPSECDOI_ATTR_GRP_DESC, "Group Description", NULL },
422 { IPSECDOI_ATTR_ENC_MODE, "Encription Mode", s_ipsecdoi_encmode },
423 { IPSECDOI_ATTR_AUTH, "Authentication Algorithm", s_ipsecdoi_auth },
424 { IPSECDOI_ATTR_KEY_LENGTH, "Key Length", NULL },
425 { IPSECDOI_ATTR_KEY_ROUNDS, "Key Rounds", NULL },
426 { IPSECDOI_ATTR_COMP_DICT_SIZE, "Compression Dictionary Size", NULL },
427 { IPSECDOI_ATTR_COMP_PRIVALG, "Compression Private Algorithm", NULL },
428 };
429
430 char *
431 s_ipsecdoi_attr(k)
432 int k;
433 {
434 int i;
435 for (i = 0; i < ARRAYLEN(name_attr_ipsec); i++)
436 if (name_attr_ipsec[i].key == k)
437 return name_attr_ipsec[i].str;
438 return num2str(k);
439 }
440
441 static struct ksmap name_attr_ipsec_ltype[] = {
442 { IPSECDOI_ATTR_SA_LD_TYPE_SEC, "seconds", NULL },
443 { IPSECDOI_ATTR_SA_LD_TYPE_KB, "kilobytes", NULL },
444 };
445
446 char *
447 s_ipsecdoi_ltype(k)
448 int k;
449 {
450 int i;
451 for (i = 0; i < ARRAYLEN(name_attr_ipsec_ltype); i++)
452 if (name_attr_ipsec_ltype[i].key == k)
453 return name_attr_ipsec_ltype[i].str;
454 return num2str(k);
455 }
456
457 static struct ksmap name_attr_ipsec_encmode[] = {
458 { IPSECDOI_ATTR_ENC_MODE_ANY, "Any", NULL },
459 { IPSECDOI_ATTR_ENC_MODE_TUNNEL, "Tunnel", NULL },
460 { IPSECDOI_ATTR_ENC_MODE_TRNS, "Transport", NULL },
461 { IPSECDOI_ATTR_ENC_MODE_UDP_TUNNEL, "UDP Encapsulated Tunnel", NULL },
462 { IPSECDOI_ATTR_ENC_MODE_UDP_TRNS, "UDP Encapsulated Transport", NULL },
463 };
464
465 char *
466 s_ipsecdoi_encmode(k)
467 int k;
468 {
469 int i;
470 for (i = 0; i < ARRAYLEN(name_attr_ipsec_encmode); i++)
471 if (name_attr_ipsec_encmode[i].key == k)
472 return name_attr_ipsec_encmode[i].str;
473 return num2str(k);
474 }
475
476 static struct ksmap name_attr_ipsec_auth[] = {
477 { IPSECDOI_ATTR_AUTH_HMAC_MD5, "hmac-md5", NULL },
478 { IPSECDOI_ATTR_AUTH_HMAC_SHA1, "hmac-sha", NULL },
479 { IPSECDOI_ATTR_AUTH_DES_MAC, "des-mac", NULL },
480 { IPSECDOI_ATTR_AUTH_KPDK, "kpdk", NULL },
481 };
482
483 char *
484 s_ipsecdoi_auth(k)
485 int k;
486 {
487 int i;
488 for (i = 0; i < ARRAYLEN(name_attr_ipsec_auth); i++)
489 if (name_attr_ipsec_auth[i].key == k)
490 return name_attr_ipsec_auth[i].str;
491 return num2str(k);
492 }
493
494 char *
495 s_ipsecdoi_attr_v(type, val)
496 int type, val;
497 {
498 int i;
499 for (i = 0; i < ARRAYLEN(name_ipsecdoi_proto); i++)
500 if (name_attr_ipsec[i].key == type
501 && name_attr_ipsec[i].f)
502 return (name_attr_ipsec[i].f)(val);
503 return num2str(val);
504 }
505
506 static struct ksmap name_ipsecdoi_ident[] = {
507 { IPSECDOI_ID_IPV4_ADDR, "IPv4_address", NULL },
508 { IPSECDOI_ID_FQDN, "FQDN", NULL },
509 { IPSECDOI_ID_USER_FQDN, "User_FQDN", NULL },
510 { IPSECDOI_ID_IPV4_ADDR_SUBNET, "IPv4_subnet", NULL },
511 { IPSECDOI_ID_IPV6_ADDR, "IPv6_address", NULL },
512 { IPSECDOI_ID_IPV6_ADDR_SUBNET, "IPv6_subnet", NULL },
513 { IPSECDOI_ID_IPV4_ADDR_RANGE, "IPv4_address_range", NULL },
514 { IPSECDOI_ID_IPV6_ADDR_RANGE, "IPv6_address_range", NULL },
515 { IPSECDOI_ID_DER_ASN1_DN, "DER_ASN1_DN", NULL },
516 { IPSECDOI_ID_DER_ASN1_GN, "DER_ASN1_GN", NULL },
517 { IPSECDOI_ID_KEY_ID, "KEY_ID", NULL },
518 };
519
520 char *
521 s_ipsecdoi_ident(k)
522 int k;
523 {
524 int i;
525 for (i = 0; i < ARRAYLEN(name_ipsecdoi_ident); i++)
526 if (name_ipsecdoi_ident[i].key == k)
527 return name_ipsecdoi_ident[i].str;
528 return num2str(k);
529 }
530
531 /* oakley.h */
532 static struct ksmap name_oakley_attr[] = {
533 { OAKLEY_ATTR_ENC_ALG, "Encryption Algorithm", s_attr_isakmp_enc },
534 { OAKLEY_ATTR_HASH_ALG, "Hash Algorithm", s_attr_isakmp_hash },
535 { OAKLEY_ATTR_AUTH_METHOD, "Authentication Method", s_oakley_attr_method },
536 { OAKLEY_ATTR_GRP_DESC, "Group Description", s_attr_isakmp_desc },
537 { OAKLEY_ATTR_GRP_TYPE, "Group Type", s_attr_isakmp_group },
538 { OAKLEY_ATTR_GRP_PI, "Group Prime/Irreducible Polynomial", NULL },
539 { OAKLEY_ATTR_GRP_GEN_ONE, "Group Generator One", NULL },
540 { OAKLEY_ATTR_GRP_GEN_TWO, "Group Generator Two", NULL },
541 { OAKLEY_ATTR_GRP_CURVE_A, "Group Curve A", NULL },
542 { OAKLEY_ATTR_GRP_CURVE_B, "Group Curve B", NULL },
543 { OAKLEY_ATTR_SA_LD_TYPE, "Life Type", s_attr_isakmp_ltype },
544 { OAKLEY_ATTR_SA_LD, "Life Duration", NULL },
545 { OAKLEY_ATTR_PRF, "PRF", NULL },
546 { OAKLEY_ATTR_KEY_LEN, "Key Length", NULL },
547 { OAKLEY_ATTR_FIELD_SIZE, "Field Size", NULL },
548 { OAKLEY_ATTR_GRP_ORDER, "Group Order", NULL },
549 { OAKLEY_ATTR_BLOCK_SIZE, "Block Size", NULL },
550 { OAKLEY_ATTR_GSS_ID, "GSS-API endpoint name",NULL },
551 };
552
553 char *
554 s_oakley_attr(k)
555 int k;
556 {
557 int i;
558 for (i = 0; i < ARRAYLEN(name_oakley_attr); i++)
559 if (name_oakley_attr[i].key == k)
560 return name_oakley_attr[i].str;
561 return num2str(k);
562 }
563
564 static struct ksmap name_attr_isakmp_enc[] = {
565 { OAKLEY_ATTR_ENC_ALG_DES, "DES-CBC", NULL },
566 { OAKLEY_ATTR_ENC_ALG_IDEA, "IDEA-CBC", NULL },
567 { OAKLEY_ATTR_ENC_ALG_BLOWFISH, "Blowfish-CBC", NULL },
568 { OAKLEY_ATTR_ENC_ALG_RC5, "RC5-R16-B64-CBC", NULL },
569 { OAKLEY_ATTR_ENC_ALG_3DES, "3DES-CBC", NULL },
570 { OAKLEY_ATTR_ENC_ALG_CAST, "CAST-CBC", NULL },
571 };
572
573 char *
574 s_attr_isakmp_enc(k)
575 int k;
576 {
577 int i;
578 for (i = 0; i < ARRAYLEN(name_attr_isakmp_enc); i++)
579 if (name_attr_isakmp_enc[i].key == k)
580 return name_attr_isakmp_enc[i].str;
581 return num2str(k);
582 }
583
584 static struct ksmap name_attr_isakmp_hash[] = {
585 { OAKLEY_ATTR_HASH_ALG_MD5, "MD5", NULL },
586 { OAKLEY_ATTR_HASH_ALG_SHA, "SHA", NULL },
587 { OAKLEY_ATTR_HASH_ALG_TIGER, "Tiger", NULL },
588 };
589
590 char *
591 s_attr_isakmp_hash(k)
592 int k;
593 {
594 int i;
595 for (i = 0; i < ARRAYLEN(name_attr_isakmp_hash); i++)
596 if (name_attr_isakmp_hash[i].key == k)
597 return name_attr_isakmp_hash[i].str;
598 return num2str(k);
599 }
600
601 static struct ksmap name_attr_isakmp_method[] = {
602 { OAKLEY_ATTR_AUTH_METHOD_PSKEY, "pre-shared key", NULL },
603 { OAKLEY_ATTR_AUTH_METHOD_DSSSIG, "DSS signatures", NULL },
604 { OAKLEY_ATTR_AUTH_METHOD_RSASIG, "RSA signatures", NULL },
605 { OAKLEY_ATTR_AUTH_METHOD_RSAENC, "Encryption with RSA", NULL },
606 { OAKLEY_ATTR_AUTH_METHOD_RSAREV, "Revised encryption with RSA", NULL },
607 { OAKLEY_ATTR_AUTH_METHOD_EGENC, "Encryption with El-Gamal", NULL },
608 { OAKLEY_ATTR_AUTH_METHOD_EGREV, "Revised encryption with El-Gamal", NULL },
609 { OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB, "GSS-API on Kerberos 5", NULL },
610 };
611
612 char *
613 s_oakley_attr_method(k)
614 int k;
615 {
616 int i;
617 for (i = 0; i < ARRAYLEN(name_attr_isakmp_method); i++)
618 if (name_attr_isakmp_method[i].key == k)
619 return name_attr_isakmp_method[i].str;
620 return num2str(k);
621 }
622
623 static struct ksmap name_attr_isakmp_desc[] = {
624 { OAKLEY_ATTR_GRP_DESC_MODP768, "768-bit MODP group", NULL },
625 { OAKLEY_ATTR_GRP_DESC_MODP1024, "1024-bit MODP group", NULL },
626 { OAKLEY_ATTR_GRP_DESC_EC2N155, "EC2N group on GP[2^155]", NULL },
627 { OAKLEY_ATTR_GRP_DESC_EC2N185, "EC2N group on GP[2^185]", NULL },
628 { OAKLEY_ATTR_GRP_DESC_MODP1536, "1536-bit MODP group", NULL },
629 { OAKLEY_ATTR_GRP_DESC_MODP2048, "2048-bit MODP group", NULL },
630 { OAKLEY_ATTR_GRP_DESC_MODP3072, "3072-bit MODP group", NULL },
631 { OAKLEY_ATTR_GRP_DESC_MODP4096, "4096-bit MODP group", NULL },
632 { OAKLEY_ATTR_GRP_DESC_MODP6144, "6144-bit MODP group", NULL },
633 { OAKLEY_ATTR_GRP_DESC_MODP8192, "8192-bit MODP group", NULL },
634 };
635
636 char *
637 s_attr_isakmp_desc(k)
638 int k;
639 {
640 int i;
641 for (i = 0; i < ARRAYLEN(name_attr_isakmp_desc); i++)
642 if (name_attr_isakmp_desc[i].key == k)
643 return name_attr_isakmp_desc[i].str;
644 return num2str(k);
645 }
646
647 static struct ksmap name_attr_isakmp_group[] = {
648 { OAKLEY_ATTR_GRP_TYPE_MODP, "MODP", NULL },
649 { OAKLEY_ATTR_GRP_TYPE_ECP, "ECP", NULL },
650 { OAKLEY_ATTR_GRP_TYPE_EC2N, "EC2N", NULL },
651 };
652
653 char *
654 s_attr_isakmp_group(k)
655 int k;
656 {
657 int i;
658 for (i = 0; i < ARRAYLEN(name_attr_isakmp_group); i++)
659 if (name_attr_isakmp_group[i].key == k)
660 return name_attr_isakmp_group[i].str;
661 return num2str(k);
662 }
663
664 static struct ksmap name_attr_isakmp_ltype[] = {
665 { OAKLEY_ATTR_SA_LD_TYPE_SEC, "seconds", NULL },
666 { OAKLEY_ATTR_SA_LD_TYPE_KB, "kilobytes", NULL },
667 };
668
669 char *
670 s_attr_isakmp_ltype(k)
671 int k;
672 {
673 int i;
674 for (i = 0; i < ARRAYLEN(name_attr_isakmp_ltype); i++)
675 if (name_attr_isakmp_ltype[i].key == k)
676 return name_attr_isakmp_ltype[i].str;
677 return num2str(k);
678 }
679
680 char *
681 s_oakley_attr_v(type, val)
682 int type, val;
683 {
684 int i;
685 for (i = 0; i < ARRAYLEN(name_oakley_attr); i++)
686 if (name_oakley_attr[i].key == type
687 && name_oakley_attr[i].f)
688 return (name_oakley_attr[i].f)(val);
689 return num2str(val);
690 }
691
692 /* netinet6/ipsec.h */
693 static struct ksmap name_ipsec_level[] = {
694 { IPSEC_LEVEL_USE, "use", NULL },
695 { IPSEC_LEVEL_REQUIRE, "require", NULL },
696 { IPSEC_LEVEL_UNIQUE, "unique", NULL },
697 };
698
699 char *
700 s_ipsec_level(k)
701 int k;
702 {
703 int i;
704 for (i = 0; i < ARRAYLEN(name_ipsec_level); i++)
705 if (name_ipsec_level[i].key == k)
706 return name_ipsec_level[i].str;
707 return num2str(k);
708 }
709
710 static struct ksmap name_algclass[] = {
711 { algclass_ipsec_enc, "ipsec enc", s_ipsecdoi_trns_esp },
712 { algclass_ipsec_auth, "ipsec auth", s_ipsecdoi_trns_ah },
713 { algclass_ipsec_comp, "ipsec comp", s_ipsecdoi_trns_ipcomp },
714 { algclass_isakmp_enc, "isakmp enc", s_attr_isakmp_enc },
715 { algclass_isakmp_hash, "isakmp hash", s_attr_isakmp_hash },
716 { algclass_isakmp_dh, "isakmp dh", s_attr_isakmp_desc },
717 { algclass_isakmp_ameth, "isakmp auth method", s_oakley_attr_method },
718 };
719
720 char *
721 s_algclass(k)
722 int k;
723 {
724 int i;
725 for (i = 0; i < ARRAYLEN(name_algclass); i++)
726 if (name_algclass[i].key == k)
727 return name_algclass[i].str;
728 return num2str(k);
729 }
730
731 char *
732 s_algtype(class, n)
733 int class, n;
734 {
735 int i;
736 for (i = 0; i < ARRAYLEN(name_algclass); i++)
737 if (name_algclass[i].key == class
738 && name_algclass[i].f)
739 return (name_algclass[i].f)(n);
740 return num2str(n);
741 }
742
743 /* pfkey.h */
744 static struct ksmap name_pfkey_type[] = {
745 { SADB_GETSPI, "GETSPI", NULL },
746 { SADB_UPDATE, "UPDATE", NULL },
747 { SADB_ADD, "ADD", NULL },
748 { SADB_DELETE, "DELETE", NULL },
749 { SADB_GET, "GET", NULL },
750 { SADB_ACQUIRE, "ACQUIRE", NULL },
751 { SADB_REGISTER, "REGISTER", NULL },
752 { SADB_EXPIRE, "EXPIRE", NULL },
753 { SADB_FLUSH, "FLUSH", NULL },
754 { SADB_DUMP, "DUMP", NULL },
755 { SADB_X_PROMISC, "X_PRIMISC", NULL },
756 { SADB_X_PCHANGE, "X_PCHANGE", NULL },
757 { SADB_X_SPDUPDATE, "X_SPDUPDATE", NULL },
758 { SADB_X_SPDADD, "X_SPDADD", NULL },
759 { SADB_X_SPDDELETE, "X_SPDDELETE", NULL },
760 { SADB_X_SPDGET, "X_SPDGET", NULL },
761 { SADB_X_SPDACQUIRE, "X_SPDACQUIRE", NULL },
762 { SADB_X_SPDDUMP, "X_SPDDUMP", NULL },
763 { SADB_X_SPDFLUSH, "X_SPDFLUSH", NULL },
764 { SADB_X_SPDSETIDX, "X_SPDSETIDX", NULL },
765 { SADB_X_SPDEXPIRE, "X_SPDEXPIRE", NULL },
766 { SADB_X_SPDDELETE2, "X_SPDDELETE2", NULL },
767 };
768
769 char *
770 s_pfkey_type(k)
771 int k;
772 {
773 int i;
774 for (i = 0; i < ARRAYLEN(name_pfkey_type); i++)
775 if (name_pfkey_type[i].key == k)
776 return name_pfkey_type[i].str;
777 return num2str(k);
778 }
779
780 static struct ksmap name_pfkey_satype[] = {
781 { SADB_SATYPE_UNSPEC, "UNSPEC", NULL },
782 { SADB_SATYPE_AH, "AH", NULL },
783 { SADB_SATYPE_ESP, "ESP", NULL },
784 { SADB_SATYPE_RSVP, "RSVP", NULL },
785 { SADB_SATYPE_OSPFV2, "OSPFV2", NULL },
786 { SADB_SATYPE_RIPV2, "RIPV2", NULL },
787 { SADB_SATYPE_MIP, "MIP", NULL },
788 { SADB_X_SATYPE_IPCOMP, "IPCOMP", NULL },
789 };
790
791 char *
792 s_pfkey_satype(k)
793 int k;
794 {
795 int i;
796 for (i = 0; i < ARRAYLEN(name_pfkey_satype); i++)
797 if (name_pfkey_satype[i].key == k)
798 return name_pfkey_satype[i].str;
799 return num2str(k);
800 }
801
802 static struct ksmap name_direction[] = {
803 { IPSEC_DIR_INBOUND, "in", NULL },
804 { IPSEC_DIR_OUTBOUND, "out", NULL },
805 };
806
807 char *
808 s_direction(k)
809 int k;
810 {
811 int i;
812 for (i = 0; i < ARRAYLEN(name_direction); i++)
813 if (name_direction[i].key == k)
814 return name_direction[i].str;
815 return num2str(k);
816 }
817
818 char *
819 s_proto(k)
820 int k;
821 {
822 switch (k) {
823 case IPPROTO_ICMP:
824 return "icmp";
825 case IPPROTO_TCP:
826 return "tcp";
827 case IPPROTO_UDP:
828 return "udp";
829 case IPPROTO_ICMPV6:
830 return "icmpv6";
831 case IPSEC_ULPROTO_ANY:
832 return "any";
833 }
834
835 return num2str(k);
836 }