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