7ae04e0c46203f1960e6771bff57763c7dcec68e
[strongswan.git] / src / pluto / constants.c
1 /* tables of names for values defined in constants.h
2 * Copyright (C) 1998-2002 D. Hugh Redelmeier.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * RCSID $Id$
15 */
16
17 /*
18 * Note that the array sizes are all specified; this is to enable range
19 * checking by code that only includes constants.h.
20 */
21
22 #include <stddef.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include <netinet/in.h>
26
27 #include <freeswan.h>
28 #include <ipsec_policy.h>
29
30 #include "constants.h"
31 #include "defs.h"
32 #include "log.h"
33 #include "packet.h"
34
35 /* string naming compile-time options that have interop implications */
36
37 const char compile_time_interop_options[] = ""
38 #ifdef THREADS
39 " THREADS"
40 #endif
41 #ifdef LIBCURL
42 " LIBCURL"
43 #endif
44 #ifdef LIBLDAP
45 " LIBLDAP"
46 #endif
47 #ifdef SMARTCARD
48 " SMARTCARD"
49 #endif
50 #ifdef VENDORID
51 " VENDORID"
52 #endif
53 #ifdef CISCO_QUIRKS
54 " CISCO_QUIRKS"
55 #endif
56 #ifdef USE_KEYRR
57 " KEYRR"
58 #endif
59 ;
60
61 /* version */
62
63 static const char *const version_name[] = {
64 "ISAKMP Version 1.0",
65 };
66
67 enum_names version_names =
68 { ISAKMP_MAJOR_VERSION<<ISA_MAJ_SHIFT | ISAKMP_MINOR_VERSION,
69 ISAKMP_MAJOR_VERSION<<ISA_MAJ_SHIFT | ISAKMP_MINOR_VERSION,
70 version_name, NULL };
71
72 /* RFC 2459 CRL reason codes */
73
74 static const char *const crl_reason_name[] = {
75 "unspecified",
76 "key compromise",
77 "ca compromise",
78 "affiliation changed",
79 "superseded",
80 "cessation of operation",
81 "certificate hold",
82 "reason #7",
83 "remove from crl"
84 };
85
86 enum_names crl_reason_names =
87 { REASON_UNSPECIFIED, REASON_REMOVE_FROM_CRL, crl_reason_name, NULL};
88
89 /* RFC 3706 Dead Peer Detection */
90
91 static const char *const dpd_action_name[] = {
92 "none",
93 "clear",
94 "hold",
95 "restart"
96 };
97
98 enum_names dpd_action_names =
99 { DPD_ACTION_NONE, DPD_ACTION_RESTART, dpd_action_name, NULL};
100
101 /* Timer events */
102
103 static const char *const timer_event_name[] = {
104 "EVENT_NULL",
105 "EVENT_REINIT_SECRET",
106 "EVENT_SHUNT_SCAN",
107 "EVENT_SO_DISCARD",
108 "EVENT_RETRANSMIT",
109 "EVENT_SA_REPLACE",
110 "EVENT_SA_REPLACE_IF_USED",
111 "EVENT_SA_EXPIRE",
112 "EVENT_NAT_T_KEEPALIVE",
113 "EVENT_DPD",
114 "EVENT_DPD_TIMEOUT",
115 "EVENT_LOG_DAILY"
116 };
117
118 enum_names timer_event_names =
119 { EVENT_NULL, EVENT_LOG_DAILY, timer_event_name, NULL };
120
121 /* Domain of Interpretation */
122
123 static const char *const doi_name[] = {
124 "ISAKMP_DOI_ISAKMP",
125 "ISAKMP_DOI_IPSEC",
126 };
127
128 enum_names doi_names = { ISAKMP_DOI_ISAKMP, ISAKMP_DOI_IPSEC, doi_name, NULL };
129
130 /* debugging settings: a set of selections for reporting
131 * These would be more naturally situated in log.h,
132 * but they are shared with whack.
133 * It turns out that "debug-" is clutter in all contexts this is used,
134 * so we leave it off.
135 */
136 #ifdef DEBUG
137 const char *const debug_bit_names[] = {
138 "raw",
139 "crypt",
140 "parsing",
141 "emitting",
142 "control",
143 "lifecycle",
144 "klips",
145 "dns",
146 "natt",
147 "oppo",
148 "controlmore",
149
150 "private",
151
152 "impair-delay-adns-key-answer",
153 "impair-delay-adns-txt-answer",
154 "impair-bust-mi2",
155 "impair-bust-mr2",
156
157 NULL
158 };
159 #endif
160
161 /* State of exchanges */
162
163 static const char *const state_name[] = {
164 "STATE_MAIN_R0",
165 "STATE_MAIN_I1",
166 "STATE_MAIN_R1",
167 "STATE_MAIN_I2",
168 "STATE_MAIN_R2",
169 "STATE_MAIN_I3",
170 "STATE_MAIN_R3",
171 "STATE_MAIN_I4",
172
173 "STATE_QUICK_R0",
174 "STATE_QUICK_I1",
175 "STATE_QUICK_R1",
176 "STATE_QUICK_I2",
177 "STATE_QUICK_R2",
178
179 "STATE_INFO",
180 "STATE_INFO_PROTECTED",
181
182 "STATE_XAUTH_I0",
183 "STATE_XAUTH_R1",
184 "STATE_XAUTH_I1",
185 "STATE_XAUTH_R2",
186 "STATE_XAUTH_I2",
187 "STATE_XAUTH_R3",
188
189 "STATE_MODE_CFG_R0",
190 "STATE_MODE_CFG_I1",
191 "STATE_MODE_CFG_R1",
192 "STATE_MODE_CFG_I2",
193
194 "STATE_MODE_CFG_I0",
195 "STATE_MODE_CFG_R3",
196 "STATE_MODE_CFG_I3",
197 "STATE_MODE_CFG_R4",
198
199 "STATE_IKE_ROOF"
200 };
201
202 enum_names state_names =
203 { STATE_MAIN_R0, STATE_IKE_ROOF-1, state_name, NULL };
204
205 /* story for state */
206
207 const char *const state_story[] = {
208 "expecting MI1", /* STATE_MAIN_R0 */
209 "sent MI1, expecting MR1", /* STATE_MAIN_I1 */
210 "sent MR1, expecting MI2", /* STATE_MAIN_R1 */
211 "sent MI2, expecting MR2", /* STATE_MAIN_I2 */
212 "sent MR2, expecting MI3", /* STATE_MAIN_R2 */
213 "sent MI3, expecting MR3", /* STATE_MAIN_I3 */
214 "sent MR3, ISAKMP SA established", /* STATE_MAIN_R3 */
215 "ISAKMP SA established", /* STATE_MAIN_I4 */
216
217 "expecting QI1", /* STATE_QUICK_R0 */
218 "sent QI1, expecting QR1", /* STATE_QUICK_I1 */
219 "sent QR1, inbound IPsec SA installed, expecting QI2", /* STATE_QUICK_R1 */
220 "sent QI2, IPsec SA established", /* STATE_QUICK_I2 */
221 "IPsec SA established", /* STATE_QUICK_R2 */
222
223 "got Informational Message in clear", /* STATE_INFO */
224 "got encrypted Informational Message", /* STATE_INFO_PROTECTED */
225
226 "expecting XAUTH request", /* STATE_XAUTH_I0 */
227 "sent XAUTH request, expecting reply", /* STATE_XAUTH_R1 */
228 "sent XAUTH reply, expecting status", /* STATE_XAUTH_I1 */
229 "sent XAUTH status, expecting ack", /* STATE_XAUTH_R2 */
230 "sent XAUTH ack, established", /* STATE_XAUTH_I2 */
231 "received XAUTH ack, established", /* STATE_XAUTH_R3 */
232
233 "expecting ModeCfg request", /* STATE_MODE_CFG_R0 */
234 "sent ModeCfg request, expecting reply", /* STATE_MODE_CFG_I1 */
235 "sent ModeCfg reply, established", /* STATE_MODE_CFG_R1 */
236 "received ModeCfg reply, established", /* STATE_MODE_CFG_I2 */
237
238 "expecting ModeCfg set", /* STATE_MODE_CFG_I0 */
239 "sent ModeCfg set, expecting ack", /* STATE_MODE_CFG_R3 */
240 "sent ModeCfg ack, established", /* STATE_MODE_CFG_I3 */
241 "received ModeCfg ack, established", /* STATE_MODE_CFG_R4 */
242 };
243
244 /* kind of struct connection */
245
246 static const char *const connection_kind_name[] = {
247 "CK_GROUP", /* policy group: instantiates to template */
248 "CK_TEMPLATE", /* abstract connection, with wildcard */
249 "CK_PERMANENT", /* normal connection */
250 "CK_INSTANCE", /* instance of template, created for a particular attempt */
251 "CK_GOING_AWAY" /* instance being deleted -- don't delete again */
252 };
253
254 enum_names connection_kind_names =
255 { CK_GROUP, CK_GOING_AWAY, connection_kind_name, NULL };
256
257 /* routing status names */
258
259 static const char *const routing_story_strings[] = {
260 "unrouted", /* RT_UNROUTED: unrouted */
261 "unrouted HOLD", /* RT_UNROUTED_HOLD: unrouted, but HOLD shunt installed */
262 "eroute eclipsed", /* RT_ROUTED_ECLIPSED: RT_ROUTED_PROSPECTIVE except bare HOLD or instance has eroute */
263 "prospective erouted", /* RT_ROUTED_PROSPECTIVE: routed, and prospective shunt installed */
264 "erouted HOLD", /* RT_ROUTED_HOLD: routed, and HOLD shunt installed */
265 "fail erouted", /* RT_ROUTED_FAILURE: routed, and failure-context shunt eroute installed */
266 "erouted", /* RT_ROUTED_TUNNEL: routed, and erouted to an IPSEC SA group */
267 "keyed, unrouted", /* RT_UNROUTED_KEYED: was routed+keyed, but it got turned into an outer policy */
268 };
269
270 enum_names routing_story =
271 { RT_UNROUTED, RT_ROUTED_TUNNEL, routing_story_strings, NULL};
272
273 /* Payload types (RFC 2408 "ISAKMP" section 3.1) */
274
275 const char *const payload_name[] = {
276 "ISAKMP_NEXT_NONE",
277 "ISAKMP_NEXT_SA",
278 "ISAKMP_NEXT_P",
279 "ISAKMP_NEXT_T",
280 "ISAKMP_NEXT_KE",
281 "ISAKMP_NEXT_ID",
282 "ISAKMP_NEXT_CERT",
283 "ISAKMP_NEXT_CR",
284 "ISAKMP_NEXT_HASH",
285 "ISAKMP_NEXT_SIG",
286 "ISAKMP_NEXT_NONCE",
287 "ISAKMP_NEXT_N",
288 "ISAKMP_NEXT_D",
289 "ISAKMP_NEXT_VID",
290 "ISAKMP_NEXT_MODECFG",
291 "ISAKMP_NEXT_15",
292 "ISAKMP_NEXT_16",
293 "ISAKMP_NEXT_17",
294 "ISAKMP_NEXT_18",
295 "ISAKMP_NEXT_19",
296 "ISAKMP_NEXT_NAT-D",
297 "ISAKMP_NEXT_NAT-OA",
298 NULL
299 };
300
301 const char *const payload_name_nat_d[] = { "ISAKMP_NEXT_NAT-D",
302 "ISAKMP_NEXT_NAT-OA", NULL };
303
304 static enum_names payload_names_nat_d =
305 { ISAKMP_NEXT_NATD_DRAFTS, ISAKMP_NEXT_NATOA_DRAFTS, payload_name_nat_d, NULL };
306
307 enum_names payload_names =
308 { ISAKMP_NEXT_NONE, ISAKMP_NEXT_NATOA_RFC, payload_name, &payload_names_nat_d };
309
310 /* Exchange types (note: two discontinuous ranges) */
311
312 static const char *const exchange_name[] = {
313 "ISAKMP_XCHG_NONE",
314 "ISAKMP_XCHG_BASE",
315 "ISAKMP_XCHG_IDPROT",
316 "ISAKMP_XCHG_AO",
317 "ISAKMP_XCHG_AGGR",
318 "ISAKMP_XCHG_INFO",
319 "ISAKMP_XCHG_MODE_CFG",
320 };
321
322 static const char *const exchange_name2[] = {
323 "ISAKMP_XCHG_QUICK",
324 "ISAKMP_XCHG_NGRP",
325 "ISAKMP_XCHG_ACK_INFO",
326 };
327
328 static enum_names exchange_desc2 =
329 { ISAKMP_XCHG_QUICK, ISAKMP_XCHG_ACK_INFO, exchange_name2, NULL };
330
331 enum_names exchange_names =
332 { ISAKMP_XCHG_NONE, ISAKMP_XCHG_MODE_CFG, exchange_name, &exchange_desc2 };
333
334 /* Flag BITS */
335 const char *const flag_bit_names[] = {
336 "ISAKMP_FLAG_ENCRYPTION",
337 "ISAKMP_FLAG_COMMIT",
338 NULL
339 };
340
341 /* Situation BITS definition for IPsec DOI */
342
343 const char *const sit_bit_names[] = {
344 "SIT_IDENTITY_ONLY",
345 "SIT_SECRECY",
346 "SIT_INTEGRITY",
347 NULL
348 };
349
350 /* Protocol IDs (RFC 2407 "IPsec DOI" section 4.4.1) */
351
352 static const char *const protocol_name[] = {
353 "PROTO_ISAKMP",
354 "PROTO_IPSEC_AH",
355 "PROTO_IPSEC_ESP",
356 "PROTO_IPCOMP",
357 };
358
359 enum_names protocol_names =
360 { PROTO_ISAKMP, PROTO_IPCOMP, protocol_name, NULL };
361
362 /* IPsec ISAKMP transform values */
363
364 static const char *const isakmp_transform_name[] = {
365 "KEY_IKE",
366 };
367
368 enum_names isakmp_transformid_names =
369 { KEY_IKE, KEY_IKE, isakmp_transform_name, NULL };
370
371 /* IPsec AH transform values */
372
373 static const char *const ah_transform_name[] = {
374 "AH_MD5",
375 "AH_SHA",
376 "AH_DES",
377 "AH_SHA2_256",
378 "AH_SHA2_384",
379 "AH_SHA2_512",
380 "AH_RIPEMD",
381 "AH_AES_XCBC_MAC",
382 "AH_RSA"
383 };
384
385 enum_names ah_transformid_names =
386 { AH_MD5, AH_RSA, ah_transform_name, NULL };
387
388 /* IPsec ESP transform values */
389
390 static const char *const esp_transform_name[] = {
391 "ESP_DES_IV64",
392 "ESP_DES",
393 "ESP_3DES",
394 "ESP_RC5",
395 "ESP_IDEA",
396 "ESP_CAST",
397 "ESP_BLOWFISH",
398 "ESP_3IDEA",
399 "ESP_DES_IV32",
400 "ESP_RC4",
401 "ESP_NULL",
402 "ESP_AES",
403 "ESP_AES-CTR",
404 "ESP_AES-CCM_8",
405 "ESP_AES-CCM_12",
406 "ESP_AES-CCM_16",
407 "ESP_UNASSIGNED_17",
408 "ESP_AES_GCM_8",
409 "ESP_AES_GCM_12",
410 "ESP_AES_GCM_16",
411 "ESP_SEED_CBC",
412 "ESP_CAMELLIA"
413 };
414
415 /*
416 * ipsec drafts suggest "high" ESP ids values for testing,
417 * assign generic ESP_ID<num> if not officially defined
418 */
419 static const char *const esp_transform_name_high[] = {
420 "ESP_SERPENT",
421 "ESP_TWOFISH"
422 };
423
424 enum_names esp_transformid_names_high =
425 { ESP_SERPENT, ESP_TWOFISH, esp_transform_name_high, NULL };
426
427 enum_names esp_transformid_names =
428 { ESP_DES_IV64, ESP_CAMELLIA, esp_transform_name, &esp_transformid_names_high };
429
430 /* IPCOMP transform values */
431
432 static const char *const ipcomp_transform_name[] = {
433 "IPCOMP_OUI",
434 "IPCOMP_DEFLAT",
435 "IPCOMP_LZS",
436 "IPCOMP_LZJH",
437 };
438
439 enum_names ipcomp_transformid_names =
440 { IPCOMP_OUI, IPCOMP_LZJH, ipcomp_transform_name, NULL };
441
442 /* Identification type values */
443
444 static const char *const ident_name[] = {
445 "ID_IPV4_ADDR",
446 "ID_FQDN",
447 "ID_USER_FQDN",
448 "ID_IPV4_ADDR_SUBNET",
449 "ID_IPV6_ADDR",
450 "ID_IPV6_ADDR_SUBNET",
451 "ID_IPV4_ADDR_RANGE",
452 "ID_IPV6_ADDR_RANGE",
453 "ID_DER_ASN1_DN",
454 "ID_DER_ASN1_GN",
455 "ID_KEY_ID",
456 };
457
458 enum_names ident_names =
459 { ID_IPV4_ADDR, ID_KEY_ID, ident_name, NULL };
460
461 /* Certificate type values */
462
463 static const char *const cert_type_name[] = {
464 "CERT_NONE",
465 "CERT_PKCS7_WRAPPED_X509",
466 "CERT_PGP",
467 "CERT_DNS_SIGNED_KEY",
468 "CERT_X509_SIGNATURE",
469 "CERT_X509_KEY_EXCHANGE",
470 "CERT_KERBEROS_TOKENS",
471 "CERT_CRL",
472 "CERT_ARL",
473 "CERT_SPKI",
474 "CERT_X509_ATTRIBUTE",
475 };
476
477 enum_names cert_type_names =
478 { CERT_NONE, CERT_X509_ATTRIBUTE, cert_type_name, NULL };
479
480 /* Certificate policy names */
481
482 static const char *const cert_policy_name[] = {
483 "ALWAYS_SEND",
484 "SEND_IF_ASKED",
485 "NEVER_SEND",
486 };
487
488 enum_names cert_policy_names =
489 { CERT_ALWAYS_SEND, CERT_NEVER_SEND, cert_policy_name, NULL };
490
491 /* Goal BITs for establishing an SA
492 * Note: we drop the POLICY_ prefix so that logs are more concise.
493 */
494
495 const char *const sa_policy_bit_names[] = {
496 "PSK",
497 "RSASIG",
498 "ENCRYPT",
499 "AUTHENTICATE",
500 "COMPRESS",
501 "TUNNEL",
502 "PFS",
503 "DISABLEARRIVALCHECK",
504 "SHUNT0",
505 "SHUNT1",
506 "FAILSHUNT0",
507 "FAILSHUNT1",
508 "DONTREKEY",
509 "OPPORTUNISTIC",
510 "GROUP",
511 "GROUTED",
512 "UP",
513 "MODECFGPUSH",
514 "XAUTHPSK",
515 "XAUTHRSASIG",
516 "XAUTHSERVER",
517 "DONTREAUTH",
518 "BEET",
519 "MOBIKE",
520 "ECDSA",
521 "PROXY",
522 NULL
523 };
524
525 const char *const policy_shunt_names[4] = {
526 "TRAP",
527 "PASS",
528 "DROP",
529 "REJECT",
530 };
531
532 const char *const policy_fail_names[4] = {
533 "NONE",
534 "PASS",
535 "DROP",
536 "REJECT",
537 };
538
539 /* Oakley transform attributes
540 * oakley_attr_bit_names does double duty: it is used for enum names
541 * and bit names.
542 */
543
544 const char *const oakley_attr_bit_names[] = {
545 "OAKLEY_ENCRYPTION_ALGORITHM",
546 "OAKLEY_HASH_ALGORITHM",
547 "OAKLEY_AUTHENTICATION_METHOD",
548 "OAKLEY_GROUP_DESCRIPTION",
549 "OAKLEY_GROUP_TYPE",
550 "OAKLEY_GROUP_PRIME",
551 "OAKLEY_GROUP_GENERATOR_ONE",
552 "OAKLEY_GROUP_GENERATOR_TWO",
553 "OAKLEY_GROUP_CURVE_A",
554 "OAKLEY_GROUP_CURVE_B",
555 "OAKLEY_LIFE_TYPE",
556 "OAKLEY_LIFE_DURATION",
557 "OAKLEY_PRF",
558 "OAKLEY_KEY_LENGTH",
559 "OAKLEY_FIELD_SIZE",
560 "OAKLEY_GROUP_ORDER",
561 "OAKLEY_BLOCK_SIZE",
562 NULL
563 };
564
565 static const char *const oakley_var_attr_name[] = {
566 "OAKLEY_GROUP_PRIME (variable length)",
567 "OAKLEY_GROUP_GENERATOR_ONE (variable length)",
568 "OAKLEY_GROUP_GENERATOR_TWO (variable length)",
569 "OAKLEY_GROUP_CURVE_A (variable length)",
570 "OAKLEY_GROUP_CURVE_B (variable length)",
571 NULL,
572 "OAKLEY_LIFE_DURATION (variable length)",
573 NULL,
574 NULL,
575 NULL,
576 "OAKLEY_GROUP_ORDER (variable length)",
577 };
578
579 static enum_names oakley_attr_desc_tv = {
580 OAKLEY_ENCRYPTION_ALGORITHM + ISAKMP_ATTR_AF_TV,
581 OAKLEY_GROUP_ORDER + ISAKMP_ATTR_AF_TV, oakley_attr_bit_names, NULL };
582
583 enum_names oakley_attr_names = {
584 OAKLEY_GROUP_PRIME, OAKLEY_GROUP_ORDER,
585 oakley_var_attr_name, &oakley_attr_desc_tv };
586
587 /* for each Oakley attribute, which enum_names describes its values? */
588 enum_names *oakley_attr_val_descs[] = {
589 NULL, /* (none) */
590 &oakley_enc_names, /* OAKLEY_ENCRYPTION_ALGORITHM */
591 &oakley_hash_names, /* OAKLEY_HASH_ALGORITHM */
592 &oakley_auth_names, /* OAKLEY_AUTHENTICATION_METHOD */
593 &oakley_group_names, /* OAKLEY_GROUP_DESCRIPTION */
594 &oakley_group_type_names,/* OAKLEY_GROUP_TYPE */
595 NULL, /* OAKLEY_GROUP_PRIME */
596 NULL, /* OAKLEY_GROUP_GENERATOR_ONE */
597 NULL, /* OAKLEY_GROUP_GENERATOR_TWO */
598 NULL, /* OAKLEY_GROUP_CURVE_A */
599 NULL, /* OAKLEY_GROUP_CURVE_B */
600 &oakley_lifetime_names, /* OAKLEY_LIFE_TYPE */
601 NULL, /* OAKLEY_LIFE_DURATION */
602 &oakley_prf_names, /* OAKLEY_PRF */
603 NULL, /* OAKLEY_KEY_LENGTH */
604 NULL, /* OAKLEY_FIELD_SIZE */
605 NULL, /* OAKLEY_GROUP_ORDER */
606 };
607
608 /* IPsec DOI attributes (RFC 2407 "IPsec DOI" section 4.5) */
609
610 static const char *const ipsec_attr_name[] = {
611 "SA_LIFE_TYPE",
612 "SA_LIFE_DURATION",
613 "GROUP_DESCRIPTION",
614 "ENCAPSULATION_MODE",
615 "AUTH_ALGORITHM",
616 "KEY_LENGTH",
617 "KEY_ROUNDS",
618 "COMPRESS_DICT_SIZE",
619 "COMPRESS_PRIVATE_ALG",
620 };
621
622 static const char *const ipsec_var_attr_name[] = {
623 "SA_LIFE_DURATION (variable length)",
624 NULL,
625 NULL,
626 NULL,
627 NULL,
628 NULL,
629 NULL,
630 "COMPRESS_PRIVATE_ALG (variable length)",
631 };
632
633 static enum_names ipsec_attr_desc_tv = {
634 SA_LIFE_TYPE + ISAKMP_ATTR_AF_TV,
635 COMPRESS_PRIVATE_ALG + ISAKMP_ATTR_AF_TV,
636 ipsec_attr_name, NULL };
637
638 enum_names ipsec_attr_names = {
639 SA_LIFE_DURATION, COMPRESS_PRIVATE_ALG,
640 ipsec_var_attr_name, &ipsec_attr_desc_tv };
641
642 /* for each IPsec attribute, which enum_names describes its values? */
643 enum_names *ipsec_attr_val_descs[] = {
644 NULL, /* (none) */
645 &sa_lifetime_names, /* SA_LIFE_TYPE */
646 NULL, /* SA_LIFE_DURATION */
647 &oakley_group_names, /* GROUP_DESCRIPTION */
648 &enc_mode_names, /* ENCAPSULATION_MODE */
649 &auth_alg_names, /* AUTH_ALGORITHM */
650 NULL, /* KEY_LENGTH */
651 NULL, /* KEY_ROUNDS */
652 NULL, /* COMPRESS_DICT_SIZE */
653 NULL, /* COMPRESS_PRIVATE_ALG */
654 };
655
656 /* SA Lifetime Type attribute */
657
658 static const char *const sa_lifetime_name[] = {
659 "SA_LIFE_TYPE_SECONDS",
660 "SA_LIFE_TYPE_KBYTES",
661 };
662
663 enum_names sa_lifetime_names =
664 { SA_LIFE_TYPE_SECONDS, SA_LIFE_TYPE_KBYTES, sa_lifetime_name, NULL };
665
666 /* Encapsulation Mode attribute */
667
668 static const char *const enc_mode_name[] = {
669 "ENCAPSULATION_MODE_TUNNEL",
670 "ENCAPSULATION_MODE_TRANSPORT",
671 "ENCAPSULATION_MODE_UDP_TUNNEL",
672 "ENCAPSULATION_MODE_UDP_TRANSPORT",
673 };
674
675 static const char *const enc_udp_mode_name[] = {
676 "ENCAPSULATION_MODE_UDP_TUNNEL",
677 "ENCAPSULATION_MODE_UDP_TRANSPORT",
678 };
679
680 static enum_names enc_udp_mode_names =
681 { ENCAPSULATION_MODE_UDP_TUNNEL_DRAFTS, ENCAPSULATION_MODE_UDP_TRANSPORT_DRAFTS, enc_udp_mode_name, NULL };
682
683 enum_names enc_mode_names =
684 { ENCAPSULATION_MODE_TUNNEL, ENCAPSULATION_MODE_UDP_TRANSPORT_RFC, enc_mode_name, &enc_udp_mode_names };
685
686 /* Auth Algorithm attribute */
687
688 static const char *const auth_alg_name[] = {
689 "AUTH_ALGORITHM_HMAC_MD5",
690 "AUTH_ALGORITHM_HMAC_SHA1",
691 "AUTH_ALGORITHM_DES_MAC",
692 "AUTH_ALGORITHM_KPDK",
693 "AUTH_ALGORITHM_HMAC_SHA2_256",
694 "AUTH_ALGORITHM_HMAC_SHA2_384",
695 "AUTH_ALGORITHM_HMAC_SHA2_512",
696 "AUTH_ALGORITHM_HMAC_RIPEMD",
697 "AUTH_ALGORITHM_AES_XCBC_MAC",
698 "AUTH_ALGORITHM_SIG_RSA"
699 };
700
701 static const char *const extended_auth_alg_name[] = {
702 "AUTH_ALGORITHM_NULL"
703 };
704
705 enum_names extended_auth_alg_names =
706 { AUTH_ALGORITHM_NULL, AUTH_ALGORITHM_NULL, extended_auth_alg_name, NULL };
707
708 enum_names auth_alg_names =
709 { AUTH_ALGORITHM_HMAC_MD5, AUTH_ALGORITHM_SIG_RSA, auth_alg_name
710 , &extended_auth_alg_names };
711
712 /* From draft-beaulieu-ike-xauth */
713 static const char *const xauth_type_name[] = {
714 "Generic",
715 "RADIUS-CHAP",
716 "OTP",
717 "S/KEY",
718 };
719
720 enum_names xauth_type_names =
721 { XAUTH_TYPE_GENERIC, XAUTH_TYPE_SKEY, xauth_type_name, NULL};
722
723 /* From draft-beaulieu-ike-xauth */
724 static const char *const xauth_attr_tv_name[] = {
725 "XAUTH_TYPE",
726 NULL,
727 NULL,
728 NULL,
729 NULL,
730 NULL,
731 NULL,
732 "XAUTH_STATUS",
733 };
734
735 enum_names xauth_attr_tv_names = {
736 XAUTH_TYPE + ISAKMP_ATTR_AF_TV,
737 XAUTH_STATUS + ISAKMP_ATTR_AF_TV, xauth_attr_tv_name, NULL };
738
739 static const char *const unity_attr_name[] = {
740 "UNITY_BANNER",
741 "UNITY_SAVE_PASSWD",
742 "UNITY_DEF_DOMAIN",
743 "UNITY_SPLITDNS_NAME",
744 "UNITY_SPLIT_INCLUDE",
745 "UNITY_NATT_PORT",
746 "UNITY_LOCAL_LAN",
747 "UNITY_PFS",
748 "UNITY_FW_TYPE",
749 "UNITY_BACKUP_SERVERS",
750 "UNITY_DDNS_HOSTNAME",
751 };
752
753 enum_names unity_attr_names =
754 { UNITY_BANNER , UNITY_DDNS_HOSTNAME, unity_attr_name , &xauth_attr_tv_names };
755
756
757 static const char *const xauth_attr_name[] = {
758 "XAUTH_USER_NAME",
759 "XAUTH_USER_PASSWORD",
760 "XAUTH_PASSCODE",
761 "XAUTH_MESSAGE",
762 "XAUTH_CHALLENGE",
763 "XAUTH_DOMAIN",
764 "XAUTH_STATUS (wrong TLV syntax, should be TV)",
765 "XAUTH_NEXT_PIN",
766 "XAUTH_ANSWER",
767 };
768
769 enum_names xauth_attr_names =
770 { XAUTH_USER_NAME , XAUTH_ANSWER, xauth_attr_name , &unity_attr_names };
771
772 static const char *const modecfg_attr_name[] = {
773 "INTERNAL_IP4_ADDRESS",
774 "INTERNAL_IP4_NETMASK",
775 "INTERNAL_IP4_DNS",
776 "INTERNAL_IP4_NBNS",
777 "INTERNAL_ADDRESS_EXPIRY",
778 "INTERNAL_IP4_DHCP",
779 "APPLICATION_VERSION",
780 "INTERNAL_IP6_ADDRESS",
781 "INTERNAL_IP6_NETMASK",
782 "INTERNAL_IP6_DNS",
783 "INTERNAL_IP6_NBNS",
784 "INTERNAL_IP6_DHCP",
785 "INTERNAL_IP4_SUBNET",
786 "SUPPORTED_ATTRIBUTES",
787 "INTERNAL_IP6_SUBNET",
788 };
789
790 enum_names modecfg_attr_names =
791 { INTERNAL_IP4_ADDRESS, INTERNAL_IP6_SUBNET, modecfg_attr_name , &xauth_attr_names };
792
793 /* Oakley Lifetime Type attribute */
794
795 static const char *const oakley_lifetime_name[] = {
796 "OAKLEY_LIFE_SECONDS",
797 "OAKLEY_LIFE_KILOBYTES",
798 };
799
800 enum_names oakley_lifetime_names =
801 { OAKLEY_LIFE_SECONDS, OAKLEY_LIFE_KILOBYTES, oakley_lifetime_name, NULL };
802
803 /* Oakley PRF attribute (none defined) */
804
805 enum_names oakley_prf_names =
806 { 1, 0, NULL, NULL };
807
808 /* Oakley Encryption Algorithm attribute */
809
810 static const char *const oakley_enc_name[] = {
811 "OAKLEY_DES_CBC",
812 "OAKLEY_IDEA_CBC",
813 "OAKLEY_BLOWFISH_CBC",
814 "OAKLEY_RC5_R16_B64_CBC",
815 "OAKLEY_3DES_CBC",
816 "OAKLEY_CAST_CBC",
817 "OAKLEY_AES_CBC",
818 };
819
820 #ifdef NO_EXTRA_IKE
821 enum_names oakley_enc_names =
822 { OAKLEY_DES_CBC, OAKLEY_AES_CBC, oakley_enc_name, NULL };
823 #else
824 static const char *const oakley_enc_name_draft_aes_cbc_02[] = {
825 "OAKLEY_MARS_CBC" /* 65001 */,
826 "OAKLEY_RC6_CBC" /* 65002 */,
827 "OAKLEY_ID_65003" /* 65003 */,
828 "OAKLEY_SERPENT_CBC" /* 65004 */,
829 "OAKLEY_TWOFISH_CBC" /* 65005 */,
830 };
831 static const char *const oakley_enc_name_ssh[] = {
832 "OAKLEY_TWOFISH_CBC_SSH",
833 };
834 enum_names oakley_enc_names_ssh =
835 { OAKLEY_TWOFISH_CBC_SSH, OAKLEY_TWOFISH_CBC_SSH, oakley_enc_name_ssh
836 , NULL };
837
838 enum_names oakley_enc_names_draft_aes_cbc_02 =
839 { OAKLEY_MARS_CBC, OAKLEY_TWOFISH_CBC, oakley_enc_name_draft_aes_cbc_02
840 , &oakley_enc_names_ssh };
841
842 enum_names oakley_enc_names =
843 { OAKLEY_DES_CBC, OAKLEY_AES_CBC, oakley_enc_name
844 , &oakley_enc_names_draft_aes_cbc_02 };
845 #endif
846
847 /* Oakley Hash Algorithm attribute */
848
849 static const char *const oakley_hash_name[] = {
850 "OAKLEY_MD5",
851 "OAKLEY_SHA",
852 "OAKLEY_TIGER",
853 "OAKLEY_SHA2_256",
854 "OAKLEY_SHA2_384",
855 "OAKLEY_SHA2_512",
856 };
857
858 enum_names oakley_hash_names =
859 { OAKLEY_MD5, OAKLEY_SHA2_512, oakley_hash_name, NULL };
860
861 /* Oakley Authentication Method attribute */
862
863 static const char *const oakley_auth_name1[] = {
864 "OAKLEY_PRESHARED_KEY",
865 "OAKLEY_DSS_SIG",
866 "OAKLEY_RSA_SIG",
867 "OAKLEY_RSA_ENC",
868 "OAKLEY_RSA_ENC_REV",
869 "OAKLEY_ELGAMAL_ENC",
870 "OAKLEY_ELGAMAL_ENC_REV",
871 };
872
873 static const char *const oakley_auth_name2[] = {
874 "HybridInitRSA",
875 "HybridRespRSA",
876 "HybridInitDSS",
877 "HybridRespDSS",
878 };
879
880 static const char *const oakley_auth_name3[] = {
881 "XAUTHInitPreShared",
882 "XAUTHRespPreShared",
883 "XAUTHInitDSS",
884 "XAUTHRespDSS",
885 "XAUTHInitRSA",
886 "XAUTHRespRSA",
887 "XAUTHInitRSAEncryption",
888 "XAUTHRespRSAEncryption",
889 "XAUTHInitRSARevisedEncryption",
890 "XAUTHRespRSARevisedEncryption",
891 };
892
893 static enum_names oakley_auth_names1 =
894 { OAKLEY_PRESHARED_KEY, OAKLEY_ELGAMAL_ENC_REV
895 , oakley_auth_name1, NULL };
896
897 static enum_names oakley_auth_names2 =
898 { HybridInitRSA, HybridRespDSS
899 , oakley_auth_name2, &oakley_auth_names1 };
900
901 enum_names oakley_auth_names =
902 { XAUTHInitPreShared, XAUTHRespRSARevisedEncryption
903 , oakley_auth_name3, &oakley_auth_names2 };
904
905 /* Oakley Group Description attribute */
906
907 static const char *const oakley_group_name[] = {
908 "OAKLEY_GROUP_MODP768",
909 "OAKLEY_GROUP_MODP1024",
910 "OAKLEY_GROUP_GP155",
911 "OAKLEY_GROUP_GP185",
912 "OAKLEY_GROUP_MODP1536",
913 };
914
915 static const char *const oakley_group_name_rfc3526[] = {
916 "OAKLEY_GROUP_MODP2048",
917 "OAKLEY_GROUP_MODP3072",
918 "OAKLEY_GROUP_MODP4096",
919 "OAKLEY_GROUP_MODP6144",
920 "OAKLEY_GROUP_MODP8192"
921 };
922 enum_names oakley_group_names_rfc3526 =
923 { OAKLEY_GROUP_MODP2048, OAKLEY_GROUP_MODP8192,
924 oakley_group_name_rfc3526, NULL };
925
926 enum_names oakley_group_names =
927 { OAKLEY_GROUP_MODP768, OAKLEY_GROUP_MODP1536,
928 oakley_group_name, &oakley_group_names_rfc3526 };
929
930 /* Oakley Group Type attribute */
931
932 static const char *const oakley_group_type_name[] = {
933 "OAKLEY_GROUP_TYPE_MODP",
934 "OAKLEY_GROUP_TYPE_ECP",
935 "OAKLEY_GROUP_TYPE_EC2N",
936 };
937
938 enum_names oakley_group_type_names =
939 { OAKLEY_GROUP_TYPE_MODP, OAKLEY_GROUP_TYPE_EC2N, oakley_group_type_name, NULL };
940
941 /* Notify messages -- error types */
942
943 static const char *const notification_name[] = {
944 "INVALID_PAYLOAD_TYPE",
945 "DOI_NOT_SUPPORTED",
946 "SITUATION_NOT_SUPPORTED",
947 "INVALID_COOKIE",
948 "INVALID_MAJOR_VERSION",
949 "INVALID_MINOR_VERSION",
950 "INVALID_EXCHANGE_TYPE",
951 "INVALID_FLAGS",
952 "INVALID_MESSAGE_ID",
953 "INVALID_PROTOCOL_ID",
954 "INVALID_SPI",
955 "INVALID_TRANSFORM_ID",
956 "ATTRIBUTES_NOT_SUPPORTED",
957 "NO_PROPOSAL_CHOSEN",
958 "BAD_PROPOSAL_SYNTAX",
959 "PAYLOAD_MALFORMED",
960 "INVALID_KEY_INFORMATION",
961 "INVALID_ID_INFORMATION",
962 "INVALID_CERT_ENCODING",
963 "INVALID_CERTIFICATE",
964 "CERT_TYPE_UNSUPPORTED",
965 "INVALID_CERT_AUTHORITY",
966 "INVALID_HASH_INFORMATION",
967 "AUTHENTICATION_FAILED",
968 "INVALID_SIGNATURE",
969 "ADDRESS_NOTIFICATION",
970 "NOTIFY_SA_LIFETIME",
971 "CERTIFICATE_UNAVAILABLE",
972 "UNSUPPORTED_EXCHANGE_TYPE",
973 "UNEQUAL_PAYLOAD_LENGTHS",
974 };
975
976 static const char *const notification_status_name[] = {
977 "CONNECTED",
978 };
979
980 static const char *const ipsec_notification_name[] = {
981 "IPSEC_RESPONDER_LIFETIME",
982 "IPSEC_REPLAY_STATUS",
983 "IPSEC_INITIAL_CONTACT",
984 };
985
986 static const char *const notification_dpd_name[] = {
987 "R_U_THERE",
988 "R_U_THERE_ACK",
989 };
990
991 enum_names notification_dpd_names =
992 { R_U_THERE, R_U_THERE_ACK,
993 notification_dpd_name, NULL };
994
995 enum_names ipsec_notification_names =
996 { IPSEC_RESPONDER_LIFETIME, IPSEC_INITIAL_CONTACT,
997 ipsec_notification_name, &notification_dpd_names };
998
999 enum_names notification_status_names =
1000 { CONNECTED, CONNECTED,
1001 notification_status_name, &ipsec_notification_names };
1002
1003 enum_names notification_names =
1004 { INVALID_PAYLOAD_TYPE, UNEQUAL_PAYLOAD_LENGTHS,
1005 notification_name, &notification_status_names };
1006
1007 /* MODECFG
1008 * From draft-dukes-ike-mode-cfg
1009 */
1010 const char *const attr_msg_type_name[] = {
1011 "ISAKMP_CFG_RESERVED",
1012 "ISAKMP_CFG_REQUEST",
1013 "ISAKMP_CFG_REPLY",
1014 "ISAKMP_CFG_SET",
1015 "ISAKMP_CFG_ACK",
1016 NULL
1017 };
1018
1019 enum_names attr_msg_type_names =
1020 { 0 , ISAKMP_CFG_ACK, attr_msg_type_name , NULL };
1021
1022 /* socket address family info */
1023
1024 static const char *const af_inet_name[] = {
1025 "AF_INET",
1026 };
1027
1028 static const char *const af_inet6_name[] = {
1029 "AF_INET6",
1030 };
1031
1032 static enum_names af_names6 = { AF_INET6, AF_INET6, af_inet6_name, NULL };
1033
1034 enum_names af_names = { AF_INET, AF_INET, af_inet_name, &af_names6 };
1035
1036 static ip_address ipv4_any, ipv6_any;
1037 static ip_subnet ipv4_wildcard, ipv6_wildcard;
1038 static ip_subnet ipv4_all, ipv6_all;
1039
1040 const struct af_info af_inet4_info = {
1041 AF_INET,
1042 "AF_INET",
1043 sizeof(struct in_addr),
1044 sizeof(struct sockaddr_in),
1045 32,
1046 ID_IPV4_ADDR, ID_IPV4_ADDR_SUBNET, ID_IPV4_ADDR_RANGE,
1047 &ipv4_any, &ipv4_wildcard, &ipv4_all,
1048 };
1049
1050 const struct af_info af_inet6_info = {
1051 AF_INET6,
1052 "AF_INET6",
1053 sizeof(struct in6_addr),
1054 sizeof(struct sockaddr_in6),
1055 128,
1056 ID_IPV6_ADDR, ID_IPV6_ADDR_SUBNET, ID_IPV6_ADDR_RANGE,
1057 &ipv6_any, &ipv6_wildcard, &ipv6_all,
1058 };
1059
1060 const struct af_info *
1061 aftoinfo(int af)
1062 {
1063 switch (af)
1064 {
1065 case AF_INET:
1066 return &af_inet4_info;
1067 case AF_INET6:
1068 return &af_inet6_info;
1069 default:
1070 return NULL;
1071 }
1072 }
1073
1074 bool
1075 subnetisnone(const ip_subnet *sn)
1076 {
1077 ip_address base;
1078
1079 networkof(sn, &base);
1080 return isanyaddr(&base) && subnetishost(sn);
1081 }
1082
1083 /* BIND enumerated types */
1084
1085 #include <arpa/nameser.h>
1086
1087 static const char *const rr_type_name[] = {
1088 "T_A", /* 1 host address */
1089 "T_NS", /* 2 authoritative server */
1090 "T_MD", /* 3 mail destination */
1091 "T_MF", /* 4 mail forwarder */
1092 "T_CNAME", /* 5 canonical name */
1093 "T_SOA", /* 6 start of authority zone */
1094 "T_MB", /* 7 mailbox domain name */
1095 "T_MG", /* 8 mail group member */
1096 "T_MR", /* 9 mail rename name */
1097 "T_NULL", /* 10 null resource record */
1098 "T_WKS", /* 11 well known service */
1099 "T_PTR", /* 12 domain name pointer */
1100 "T_HINFO", /* 13 host information */
1101 "T_MINFO", /* 14 mailbox information */
1102 "T_MX", /* 15 mail routing information */
1103 "T_TXT", /* 16 text strings */
1104 "T_RP", /* 17 responsible person */
1105 "T_AFSDB", /* 18 AFS cell database */
1106 "T_X25", /* 19 X_25 calling address */
1107 "T_ISDN", /* 20 ISDN calling address */
1108 "T_RT", /* 21 router */
1109 "T_NSAP", /* 22 NSAP address */
1110 "T_NSAP_PTR", /* 23 reverse NSAP lookup (deprecated) */
1111 "T_SIG", /* 24 security signature */
1112 "T_KEY", /* 25 security key */
1113 "T_PX", /* 26 X.400 mail mapping */
1114 "T_GPOS", /* 27 geographical position (withdrawn) */
1115 "T_AAAA", /* 28 IP6 Address */
1116 "T_LOC", /* 29 Location Information */
1117 "T_NXT", /* 30 Next Valid Name in Zone */
1118 "T_EID", /* 31 Endpoint identifier */
1119 "T_NIMLOC", /* 32 Nimrod locator */
1120 "T_SRV", /* 33 Server selection */
1121 "T_ATMA", /* 34 ATM Address */
1122 "T_NAPTR", /* 35 Naming Authority PoinTeR */
1123 NULL
1124 };
1125
1126 enum_names rr_type_names = { T_A, T_NAPTR, rr_type_name, NULL };
1127
1128 /* Query type values which do not appear in resource records */
1129 static const char *const rr_qtype_name[] = {
1130 "T_IXFR", /* 251 incremental zone transfer */
1131 "T_AXFR", /* 252 transfer zone of authority */
1132 "T_MAILB", /* 253 transfer mailbox records */
1133 "T_MAILA", /* 254 transfer mail agent records */
1134 "T_ANY", /* 255 wildcard match */
1135 NULL
1136 };
1137
1138 enum_names rr_qtype_names = { T_IXFR, T_ANY, rr_qtype_name, &rr_type_names };
1139
1140 static const char *const rr_class_name[] = {
1141 "C_IN", /* 1 the arpa internet */
1142 NULL
1143 };
1144
1145 enum_names rr_class_names = { C_IN, C_IN, rr_class_name, NULL };
1146
1147 /*
1148 * NAT-Traversal defines for nat_traveral type from nat_traversal.h
1149 *
1150 */
1151 const char *const natt_type_bitnames[] = {
1152 "draft-ietf-ipsec-nat-t-ike-00/01", /* 0 */
1153 "draft-ietf-ipsec-nat-t-ike-02/03",
1154 "RFC 3947",
1155 "3", /* 3 */
1156 "4", "5", "6", "7",
1157 "8", "9", "10", "11",
1158 "12", "13", "14", "15",
1159 "16", "17", "18", "19",
1160 "20", "21", "22", "23",
1161 "24", "25", "26", "27",
1162 "28", "29",
1163 "nat is behind me",
1164 "nat is behind peer"
1165 };
1166
1167 /* look up enum names in an enum_names */
1168
1169 const char *
1170 enum_name(enum_names *ed, unsigned long val)
1171 {
1172 enum_names *p;
1173
1174 for (p = ed; p != NULL; p = p->en_next_range)
1175 {
1176 if (p->en_first <= val && val <= p->en_last)
1177 return p->en_names[val - p->en_first];
1178 }
1179 return NULL;
1180 }
1181
1182 /* find or construct a string to describe an enum value
1183 * Result may be in STATIC buffer!
1184 */
1185 const char *
1186 enum_show(enum_names *ed, unsigned long val)
1187 {
1188 const char *p = enum_name(ed, val);
1189
1190 if (p == NULL)
1191 {
1192 static char buf[12]; /* only one! I hope that it is big enough */
1193
1194 snprintf(buf, sizeof(buf), "%lu??", val);
1195 p = buf;
1196 }
1197 return p;
1198 }
1199
1200
1201 static char bitnamesbuf[200]; /* only one! I hope that it is big enough! */
1202
1203 int
1204 enum_search(enum_names *ed, const char *str)
1205 {
1206 enum_names *p;
1207 const char *ptr;
1208 unsigned en;
1209
1210 for (p = ed; p != NULL; p = p->en_next_range)
1211 {
1212 for (en = p->en_first; en <= p->en_last ;en++)
1213 {
1214 ptr = p->en_names[en - p->en_first];
1215 if (ptr == 0)
1216 {
1217 continue;
1218 }
1219 if (streq(ptr, str))
1220 {
1221 return en;
1222 }
1223 }
1224 }
1225 return -1;
1226 }
1227
1228 /* construct a string to name the bits on in a set
1229 * Result may be in STATIC buffer!
1230 * Note: prettypolicy depends on internal details.
1231 */
1232 const char *
1233 bitnamesof(const char *const table[], lset_t val)
1234 {
1235 char *p = bitnamesbuf;
1236 lset_t bit;
1237 const char *const *tp;
1238
1239 if (val == 0)
1240 return "none";
1241
1242 for (tp = table, bit = 01; val != 0; bit <<= 1)
1243 {
1244 if (val & bit)
1245 {
1246 const char *n = *tp;
1247 size_t nl;
1248
1249 if (n == NULL || *n == '\0')
1250 {
1251 /* no name for this bit, so use hex */
1252 static char flagbuf[sizeof("0x80000000")];
1253
1254 snprintf(flagbuf, sizeof(flagbuf), "0x%llx", bit);
1255 n = flagbuf;
1256 }
1257
1258 nl = strlen(n);
1259
1260 if (p != bitnamesbuf && p < bitnamesbuf+sizeof(bitnamesbuf) - 1)
1261 *p++ = '+';
1262
1263 if (bitnamesbuf+sizeof(bitnamesbuf) - p > (ptrdiff_t)nl)
1264 {
1265 strcpy(p, n);
1266 p += nl;
1267 }
1268 val -= bit;
1269 }
1270 if (*tp != NULL)
1271 tp++; /* move on, but not past end */
1272 }
1273 *p = '\0';
1274 return bitnamesbuf;
1275 }
1276
1277 /* print a policy: like bitnamesof, but it also does the non-bitfields.
1278 * Suppress the shunt and fail fields if 0.
1279 */
1280 const char *
1281 prettypolicy(lset_t policy)
1282 {
1283 const char *bn = bitnamesof(sa_policy_bit_names
1284 , policy & ~(POLICY_SHUNT_MASK | POLICY_FAIL_MASK));
1285 size_t len;
1286 lset_t shunt = (policy & POLICY_SHUNT_MASK) >> POLICY_SHUNT_SHIFT;
1287 lset_t fail = (policy & POLICY_FAIL_MASK) >> POLICY_FAIL_SHIFT;
1288
1289 if (bn != bitnamesbuf)
1290 bitnamesbuf[0] = '\0';
1291 len = strlen(bitnamesbuf);
1292 if (shunt != 0)
1293 {
1294 snprintf(bitnamesbuf + len, sizeof(bitnamesbuf) - len, "+%s"
1295 , policy_shunt_names[shunt]);
1296 len += strlen(bitnamesbuf + len);
1297 }
1298 if (fail != 0)
1299 {
1300 snprintf(bitnamesbuf + len, sizeof(bitnamesbuf) - len, "+failure%s"
1301 , policy_fail_names[fail]);
1302 len += strlen(bitnamesbuf + len);
1303 }
1304 if (NEVER_NEGOTIATE(policy))
1305 {
1306 snprintf(bitnamesbuf + len, sizeof(bitnamesbuf) - len, "+NEVER_NEGOTIATE");
1307 len += strlen(bitnamesbuf + len);
1308 }
1309 return bitnamesbuf;
1310 }
1311
1312 /* test a set by seeing if all bits have names */
1313
1314 bool
1315 testset(const char *const table[], lset_t val)
1316 {
1317 lset_t bit;
1318 const char *const *tp;
1319
1320 for (tp = table, bit = 01; val != 0; bit <<= 1, tp++)
1321 {
1322 const char *n = *tp;
1323
1324 if (n == NULL || ((val & bit) && *n == '\0'))
1325 return FALSE;
1326 val &= ~bit;
1327 }
1328 return TRUE;
1329 }
1330
1331
1332 const char sparse_end[] = "end of sparse names";
1333
1334 /* look up enum names in a sparse_names */
1335 const char *sparse_name(sparse_names sd, unsigned long val)
1336 {
1337 const struct sparse_name *p;
1338
1339 for (p = sd; p->name != sparse_end; p++)
1340 if (p->val == val)
1341 return p->name;
1342 return NULL;
1343 }
1344
1345 /* find or construct a string to describe an sparse value
1346 * Result may be in STATIC buffer!
1347 */
1348 const char *
1349 sparse_val_show(sparse_names sd, unsigned long val)
1350 {
1351 const char *p = sparse_name(sd, val);
1352
1353 if (p == NULL)
1354 {
1355 static char buf[12]; /* only one! I hope that it is big enough */
1356
1357 snprintf(buf, sizeof(buf), "%lu??", val);
1358 p = buf;
1359 }
1360 return p;
1361 }
1362
1363 void init_constants(void)
1364 {
1365 happy(anyaddr(AF_INET, &ipv4_any));
1366 happy(anyaddr(AF_INET6, &ipv6_any));
1367
1368 happy(addrtosubnet(&ipv4_any, &ipv4_wildcard));
1369 happy(addrtosubnet(&ipv6_any, &ipv6_wildcard));
1370
1371 happy(initsubnet(&ipv4_any, 0, '0', &ipv4_all));
1372 happy(initsubnet(&ipv6_any, 0, '0', &ipv6_all));
1373 }