#ifndef _IPSEC_UTIL_H
#define _IPSEC_UTIL_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <net/pfkeyv2.h>
#include <netinet/in.h>
#include <inet/ip.h>
#include <setjmp.h>
#include <stdio.h>
#include <err.h>
#include <errfp.h>
#include <net/pfpolicy.h>
#include <libtecla.h>
#ifndef A_CNT
#define A_CNT(arr) (sizeof (arr)/sizeof (arr[0]))
#define A_END(arr) (&arr[A_CNT(arr)])
#endif
#define NBUF_SIZE 16
#define COMMENT_CHAR '#'
#define CONT_CHAR '\\'
#define QUOTE_CHAR '"'
#define IBUF_SIZE 4096
#define START_ARG 8
#define TOO_MANY_ARGS (START_ARG << 9)
#define TOO_MANY_TOKENS -3
#define MEMORY_ALLOCATION -2
#define COMMENT_LINE 1
#define SUCCESS 0
#define SPC_NOSPACES 0x00000000
#define SPC_BEGIN 0x00000001
#define SPC_END 0x00000002
#define SPC_BOTH SPC_BEGIN|SPC_END
#define BYTE_STR_SIZE 16
#define SECS_STR_SIZE 20
#define TBUF_SIZE 50
#define TIME_MAX LONG_MAX
#ifndef INSECURE_PERMS
#define INSECURE_PERMS(sbuf) (((sbuf).st_uid != 0) || \
((sbuf).st_mode & S_IRWXG) || ((sbuf).st_mode & S_IRWXO))
#endif
#ifndef PKCS11_TOKSIZE
#define PKCS11_TOKSIZE 32
#endif
#define CLUSTER_UDP_PORT 2005
typedef struct keywdtab {
uint_t kw_tag;
char *kw_str;
} keywdtab_t;
typedef enum exit_type {
SERVICE_EXIT_OK,
SERVICE_DEGRADE,
SERVICE_BADPERM,
SERVICE_BADCONF,
SERVICE_MAINTAIN,
SERVICE_DISABLE,
SERVICE_FATAL,
SERVICE_RESTART,
DEBUG_FATAL
} exit_type_t;
extern void ipsecutil_exit(exit_type_t, char *, FILE *, const char *fmt, ...);
extern void bail(char *);
#define Bail(s) bail(dgettext(TEXT_DOMAIN, s))
extern void bail_msg(char *, ...);
extern int dump_sockaddr(struct sockaddr *, uint8_t, boolean_t, FILE *,
boolean_t);
extern int dump_key(uint8_t *, uint_t, uint_t, FILE *, boolean_t);
extern int dump_aalg(uint8_t, FILE *);
extern int dump_ealg(uint8_t, FILE *);
extern boolean_t dump_sadb_idtype(uint8_t, FILE *, int *);
typedef void (*parse_cmdln_fn)(int, char **, char *, boolean_t);
extern void do_interactive(FILE *, char *, char *, char *, parse_cmdln_fn,
CplMatchFn *);
extern uint_t lines_parsed;
extern uint_t lines_added;
extern int privstr2num(char *);
extern int dbgstr2num(char *);
extern int parsedbgopts(char *);
#define KMCFILE "/var/run/ipsec_kmc_map"
extern int kmc_insert_mapping(char *);
extern char *kmc_lookup_by_cookie(int);
extern boolean_t nflag;
extern boolean_t pflag;
extern boolean_t interactive;
extern boolean_t readfile;
extern uint_t lineno;
extern char numprint[NBUF_SIZE];
extern jmp_buf env;
#define INET_IPSECALGSPATH "/etc/inet/"
#define INET_IPSECALGSFILE (INET_IPSECALGSPATH "ipsecalgs")
typedef struct ipsecalgs_pkg {
int alg_num;
char *pkg_name;
} ipsecalgs_pkg_t;
typedef enum {
LIBIPSEC_ALGS_EXEC_SYNC,
LIBIPSEC_ALGS_EXEC_ASYNC
} ipsecalgs_exec_mode_t;
typedef struct ipsec_proto {
int proto_num;
char *proto_name;
char *proto_pkg;
int proto_numalgs;
struct ipsecalgent **proto_algs;
ipsecalgs_pkg_t *proto_algs_pkgs;
int proto_algs_npkgs;
ipsecalgs_exec_mode_t proto_exec_mode;
} ipsec_proto_t;
extern void _build_internal_algs(ipsec_proto_t **, int *);
extern int _str_to_ipsec_exec_mode(char *, ipsecalgs_exec_mode_t *);
extern int addipsecalg(struct ipsecalgent *, uint_t);
extern int delipsecalgbyname(const char *, int);
extern int delipsecalgbynum(int, int);
extern int addipsecproto(const char *, int, ipsecalgs_exec_mode_t, uint_t);
extern int delipsecprotobyname(const char *);
extern int delipsecprotobynum(int);
extern int *getipsecprotos(int *);
extern int *getipsecalgs(int *, int);
extern int list_ints(FILE *, int *);
extern const char *ipsecalgs_diag(int);
extern int ipsecproto_get_exec_mode(int, ipsecalgs_exec_mode_t *);
extern int ipsecproto_set_exec_mode(int, ipsecalgs_exec_mode_t);
#define LIBIPSEC_ALGS_ADD_FORCE 0x00000001
#define LIBIPSEC_ALGS_KEY_DEF_IDX 0
#define LIBIPSEC_ALGS_KEY_MIN_IDX 1
#define LIBIPSEC_ALGS_KEY_MAX_IDX 2
#define LIBIPSEC_ALGS_KEY_NUM_VAL 4
#define LIBIPSEC_ALGS_DIAG_ALG_EXISTS -1
#define LIBIPSEC_ALGS_DIAG_PROTO_EXISTS -2
#define LIBIPSEC_ALGS_DIAG_UNKN_PROTO -3
#define LIBIPSEC_ALGS_DIAG_UNKN_ALG -4
#define LIBIPSEC_ALGS_DIAG_NOMEM -5
#define LIBIPSEC_ALGS_DIAG_ALGSFILEOPEN -6
#define LIBIPSEC_ALGS_DIAG_ALGSFILEFDOPEN -7
#define LIBIPSEC_ALGS_DIAG_ALGSFILELOCK -8
#define LIBIPSEC_ALGS_DIAG_ALGSFILERENAME -9
#define LIBIPSEC_ALGS_DIAG_ALGSFILEWRITE -10
#define LIBIPSEC_ALGS_DIAG_ALGSFILECHMOD -11
#define LIBIPSEC_ALGS_DIAG_ALGSFILECHOWN -12
#define LIBIPSEC_ALGS_DIAG_ALGSFILECLOSE -13
#define LIBIPSEC_ALGS_LINE_PROTO "PROTO|"
#define LIBIPSEC_ALGS_LINE_ALG "ALG|"
#define LIBIPSEC_ALGS_LINE_PKGSTART "# Start "
#define LIBIPSEC_ALGS_LINE_PKGEND "# End "
extern int *_real_getipsecprotos(int *);
extern int *_real_getipsecalgs(int *, int);
extern struct ipsecalgent *_duplicate_alg(struct ipsecalgent *);
extern void _clean_trash(ipsec_proto_t *, int);
#define KGE_OK 0
#define KGE_DUP 1
#define KGE_UNK 2
#define KGE_LEN 3
#define KGE_CHK 4
extern int spdsock_get_ext(spd_ext_t *[], spd_msg_t *, uint_t, char *, uint_t);
extern const char *spdsock_diag(int);
extern const char *keysock_diag(int);
extern int in_masktoprefix(uint8_t *, boolean_t);
extern char *secs2out(unsigned int, char *, int, int);
extern char *secs2str(unsigned int, char *, int);
extern char *bytecnt2out(uint64_t, char *, size_t, int);
extern char *bytecnt2str(uint64_t, char *, size_t);
extern void print_diagnostic(FILE *, uint16_t);
extern void print_sadb_msg(FILE *, struct sadb_msg *, time_t, boolean_t);
extern void print_sa(FILE *, char *, struct sadb_sa *);
extern void printsatime(FILE *, int64_t, const char *, const char *,
const char *, boolean_t);
extern void print_lifetimes(FILE *, time_t, struct sadb_lifetime *,
struct sadb_lifetime *, struct sadb_lifetime *, struct sadb_lifetime *,
boolean_t vflag);
extern void print_address(FILE *, char *, struct sadb_address *, boolean_t);
extern void print_asn1_name(FILE *, const unsigned char *, long);
extern void print_key(FILE *, char *, struct sadb_key *);
extern void print_keystr(FILE *, char *, struct sadb_key *);
extern void print_ident(FILE *, char *, struct sadb_ident *);
extern void print_sens(FILE *, char *, const struct sadb_sens *, boolean_t);
extern void print_prop(FILE *, char *, struct sadb_prop *);
extern void print_eprop(FILE *, char *, struct sadb_prop *);
extern void print_supp(FILE *, char *, struct sadb_supported *);
extern void print_spirange(FILE *, char *, struct sadb_spirange *);
extern void print_kmc(FILE *, char *, struct sadb_x_kmc *);
extern void print_samsg(FILE *, uint64_t *, boolean_t, boolean_t, boolean_t);
extern char *rparsesatype(int);
extern char *rparsealg(uint8_t, int);
extern const char *rparsetcpsigalg(uint8_t);
extern char *rparseidtype(uint16_t);
extern boolean_t save_lifetime(struct sadb_lifetime *, FILE *);
extern boolean_t save_address(struct sadb_address *, FILE *);
extern boolean_t save_key(struct sadb_key *, FILE *);
extern boolean_t save_keystr(struct sadb_key *, FILE *);
extern boolean_t save_ident(struct sadb_ident *, FILE *);
extern void save_assoc(uint64_t *, FILE *);
extern FILE *opensavefile(char *);
extern const char *do_inet_ntop(const void *, char *, size_t);
extern uint8_t gettcpsigalgbyname(const char *);
extern const char *gettcpsigalgbynum(uint8_t);
#include <tsol/label.h>
extern void ipsec_convert_sens_to_bslabel(const struct sadb_sens *,
bslabel_t *);
extern int ipsec_convert_sl_to_sens(int doi, bslabel_t *, struct sadb_sens *);
extern void ipsec_convert_bslabel_to_string(bslabel_t *, char **);
extern void ipsec_convert_bslabel_to_hex(bslabel_t *, char **);
#define EXIT_OK(x) \
ipsecutil_exit(SERVICE_EXIT_OK, my_fmri, debugfile, \
dgettext(TEXT_DOMAIN, x))
#define EXIT_OK2(x, y) \
ipsecutil_exit(SERVICE_EXIT_OK, my_fmri, debugfile, \
dgettext(TEXT_DOMAIN, x), y)
#define EXIT_OK3(x, y, z) \
ipsecutil_exit(SERVICE_EXIT_OK, my_fmri, debugfile, \
dgettext(TEXT_DOMAIN, x), y, z)
#define EXIT_BADCONFIG(x) \
ipsecutil_exit(SERVICE_BADCONF, my_fmri, debugfile, \
dgettext(TEXT_DOMAIN, x))
#define EXIT_BADCONFIG2(x, y) \
ipsecutil_exit(SERVICE_BADCONF, my_fmri, debugfile, \
dgettext(TEXT_DOMAIN, x), y)
#define EXIT_BADCONFIG3(x, y, z) \
ipsecutil_exit(SERVICE_BADCONF, my_fmri, debugfile, \
dgettext(TEXT_DOMAIN, x), y, z)
#define EXIT_MAINTAIN(x) \
ipsecutil_exit(SERVICE_MAINTAIN, my_fmri, debugfile, \
dgettext(TEXT_DOMAIN, x))
#define EXIT_MAINTAIN2(x, y) \
ipsecutil_exit(SERVICE_MAINTAIN, my_fmri, debugfile, \
dgettext(TEXT_DOMAIN, x), y)
#define EXIT_DEGRADE(x) \
ipsecutil_exit(SERVICE_DEGRADE, my_fmri, debugfile, \
dgettext(TEXT_DOMAIN, x))
#define EXIT_BADPERM(x) \
ipsecutil_exit(SERVICE_BADPERM, my_fmri, debugfile, \
dgettext(TEXT_DOMAIN, x))
#define EXIT_BADPERM2(x, y) \
ipsecutil_exit(SERVICE_BADPERM, my_fmri, debugfile, \
dgettext(TEXT_DOMAIN, x), y)
#define EXIT_FATAL(x) \
ipsecutil_exit(SERVICE_FATAL, my_fmri, debugfile, \
dgettext(TEXT_DOMAIN, x))
#define EXIT_FATAL2(x, y) \
ipsecutil_exit(SERVICE_FATAL, my_fmri, debugfile, \
dgettext(TEXT_DOMAIN, x), y)
#define EXIT_FATAL3(x, y, z) \
ipsecutil_exit(SERVICE_FATAL, my_fmri, debugfile, \
dgettext(TEXT_DOMAIN, x), y, z)
#define EXIT_RESTART(x) \
ipsecutil_exit(SERVICE_RESTART, my_fmri, debugfile, \
dgettext(TEXT_DOMAIN, x))
#ifdef __cplusplus
}
#endif
#endif