3
* Copyright (C) 2004 Michael Richardson <mcr@xelerance.com>
4
* COpyright (C) 1997 Angelos D. Keromytis.
5
* Copyright (C) 1998-2002 D. Hugh Redelmeier.
7
* This program is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License as published by the
9
* Free Software Foundation; either version 2 of the License, or (at your
10
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12
* This program is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17
* RCSID $Id: constants.h,v 1.3 2004/05/29 03:06:12 mcr Exp $
23
* This file was split into internal contants (Openswan/pluto related),
24
* and external constants (defined by IETF, etc.)
26
* Constants which are kernel/IPsec related are in appropriate
27
* openswan / *.h files.
32
* NOTE:For debugging purposes, constants.c has tables to map
33
* numbers back to names.
34
* Any changes here should be reflected there.
37
#define elemsof(array) (sizeof(array) / sizeof(*(array))) /* number of elements in an array */
39
/* Many routines return only success or failure, but wish to describe
40
* the failure in a message. We use the convention that they return
41
* a NULL on success and a pointer to constant string on failure.
42
* The fact that the string is a constant is limiting, but it
43
* avoids storage management issues: the recipient is allowed to assume
44
* that the string will live "long enough" (usually forever).
45
* <openswan.h> defines err_t for this return type.
52
#define NULL_FD (-1) /* NULL file descriptor */
53
#define dup_any(fd) ((fd) == NULL_FD? NULL_FD : dup(fd))
54
#define close_any(fd) { if ((fd) != NULL_FD) { close(fd); (fd) = NULL_FD; } }
56
#define BITS_PER_BYTE 8
57
#define BYTES_FOR_BITS(b) (((b) + BITS_PER_BYTE - 1) / BITS_PER_BYTE)
59
#define streq(a, b) (strcmp((a), (b)) == 0) /* clearer shorthand */
60
#define strcaseeq(a, b) (strcasecmp((a), (b)) == 0) /* clearer shorthand */
62
/* set type with room for at least 64 elements for ALG opts (was 32 in stock FS) */
64
typedef unsigned long long lset_t;
66
#define LELEM(opt) (1ULL << (opt))
67
#define LRANGE(lwb, upb) LRANGES(LELEM(lwb), LELEM(upb))
68
#define LRANGES(first, last) (last - first + last)
69
#define LHAS(set, elem) ((LELEM(elem) & (set)) != LEMPTY)
70
#define LIN(subset, set) (((subset) & (set)) == (subset))
71
#define LDISJOINT(a, b) (((a) & (b)) == LEMPTY)
73
/* Routines to check and display values.
75
* An enum_names describes an enumeration.
76
* enum_name() returns the name of an enum value, or NULL if invalid.
77
* enum_show() is like enum_name, except it formats a numeric representation
78
* for any invalid value (in a static area!)
80
* bitnames() formats a display of a set of named bits (in a static area)
83
typedef const struct enum_names enum_names;
85
extern const char *enum_name(enum_names *ed, unsigned long val);
86
extern const char *enum_show(enum_names *ed, unsigned long val);
87
extern int enum_search(enum_names *ed, const char *string);
89
extern bool testset(const char *const table[], lset_t val);
90
extern const char *bitnamesof(const char *const table[], lset_t val);
91
extern const char *bitnamesofb(const char *const table[]
93
, char *buf, size_t blen);
96
* The sparser_name should be transformed into keyword_enum_value
98
* keyword_enum_value is used by starter()
102
#define LOOSE_ENUM_OTHER 255
104
struct keyword_enum_value {
105
const unsigned char *name;
109
struct keyword_enum_values {
110
struct keyword_enum_value *values;
114
extern const char *keyword_name(struct keyword_enum_values *kevs, unsigned int value);
116
/* sparse_names is much like enum_names, except values are
117
* not known to be contiguous or ordered.
118
* The array of names is ended with one with the name sparse_end
119
* (this avoids having to reserve a value to signify the end).
120
* Often appropriate for enums defined by others.
124
const char *const name;
127
typedef const struct sparse_name sparse_names[];
129
extern const char *sparse_name(sparse_names sd, unsigned long val);
130
extern const char *sparse_val_show(sparse_names sd, unsigned long val);
131
extern const char sparse_end[];
133
#define FULL_INET_ADDRESS_SIZE 6
135
extern void init_constants(void);
137
#include "ietf_constants.h"
138
#include "pluto_constants.h"
140
#define _CONSTANTS_H_
141
#endif /* _CONSTANTS_H_ */