17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 545916cd2Sjpk * Common Development and Distribution License (the "License"). 645916cd2Sjpk * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22c7777ac8SPaul Wernau * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _IPSEC_UTIL_H 277c478bd9Sstevel@tonic-gate #define _IPSEC_UTIL_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Headers and definitions for support functions that are shared by 317c478bd9Sstevel@tonic-gate * the ipsec utilities ipseckey and ikeadm. 327c478bd9Sstevel@tonic-gate */ 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #ifdef __cplusplus 357c478bd9Sstevel@tonic-gate extern "C" { 367c478bd9Sstevel@tonic-gate #endif 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #include <sys/types.h> 397c478bd9Sstevel@tonic-gate #include <sys/socket.h> 408810c16bSdanmcd #include <net/pfkeyv2.h> 418810c16bSdanmcd #include <netinet/in.h> 428810c16bSdanmcd #include <inet/ip.h> 437c478bd9Sstevel@tonic-gate #include <setjmp.h> 447c478bd9Sstevel@tonic-gate #include <stdio.h> 457c478bd9Sstevel@tonic-gate #include <err.h> 46d362b749Svk199839 #include <errfp.h> 477c478bd9Sstevel@tonic-gate #include <net/pfpolicy.h> 48bfe6f8f5SVladimir Kotal #include <libtecla.h> 497c478bd9Sstevel@tonic-gate 5045916cd2Sjpk #ifndef A_CNT 517c478bd9Sstevel@tonic-gate /* macros for array manipulation */ 527c478bd9Sstevel@tonic-gate #define A_CNT(arr) (sizeof (arr)/sizeof (arr[0])) 537c478bd9Sstevel@tonic-gate #define A_END(arr) (&arr[A_CNT(arr)]) 5445916cd2Sjpk #endif 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate /* used for file parsing */ 577c478bd9Sstevel@tonic-gate #define NBUF_SIZE 16 587c478bd9Sstevel@tonic-gate #define COMMENT_CHAR '#' 597c478bd9Sstevel@tonic-gate #define CONT_CHAR '\\' 607c478bd9Sstevel@tonic-gate #define QUOTE_CHAR '"' 61bfe6f8f5SVladimir Kotal /* 62bfe6f8f5SVladimir Kotal * Input buffer size limits maximum line length for both file parsing and 63bfe6f8f5SVladimir Kotal * interactive mode. 4K chars should be enough even for broad commands and 64bfe6f8f5SVladimir Kotal * all possible key lenghts of today's symmetric ciphers entered via 65bfe6f8f5SVladimir Kotal * ipseckey(1M) which has the most bifurcated grammar from all IPsec commands. 66bfe6f8f5SVladimir Kotal */ 67bfe6f8f5SVladimir Kotal #define IBUF_SIZE 4096 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate /* used for command-line parsing */ 707c478bd9Sstevel@tonic-gate #define START_ARG 8 717c478bd9Sstevel@tonic-gate #define TOO_MANY_ARGS (START_ARG << 9) 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* Return codes for argv/argc vector creation */ 747c478bd9Sstevel@tonic-gate #define TOO_MANY_TOKENS -3 757c478bd9Sstevel@tonic-gate #define MEMORY_ALLOCATION -2 767c478bd9Sstevel@tonic-gate #define COMMENT_LINE 1 777c478bd9Sstevel@tonic-gate #define SUCCESS 0 787c478bd9Sstevel@tonic-gate 79*510c3f91SVladimir Kotal /* Flags for {bytecnt,secs}2out() */ 80*510c3f91SVladimir Kotal #define SPC_NOSPACES 0x00000000 /* no space prefix/suffix */ 81*510c3f91SVladimir Kotal #define SPC_BEGIN 0x00000001 /* put space at the beginning */ 82*510c3f91SVladimir Kotal #define SPC_END 0x00000002 /* put space at the end */ 83*510c3f91SVladimir Kotal #define SPC_BOTH SPC_BEGIN|SPC_END /* print both spaces */ 84*510c3f91SVladimir Kotal 85*510c3f91SVladimir Kotal /* 86*510c3f91SVladimir Kotal * The following lengths should be sufficient for character buffers passed to 87*510c3f91SVladimir Kotal * bytecnt2str(),secs2str(). This is because the string output of these 88*510c3f91SVladimir Kotal * functions consists of limited number and units. The lengths should be also 89*510c3f91SVladimir Kotal * sufficient for bytecnt2out(),secs2out() functions. 90*510c3f91SVladimir Kotal */ 91*510c3f91SVladimir Kotal #define BYTE_STR_SIZE 16 92*510c3f91SVladimir Kotal #define SECS_STR_SIZE 20 93*510c3f91SVladimir Kotal 947c478bd9Sstevel@tonic-gate /* 957c478bd9Sstevel@tonic-gate * Time printing defines... 967c478bd9Sstevel@tonic-gate * 977c478bd9Sstevel@tonic-gate * TBUF_SIZE is pretty arbitrary. Perhaps it shouldn't be. 987c478bd9Sstevel@tonic-gate */ 997c478bd9Sstevel@tonic-gate #define TBUF_SIZE 50 1007c478bd9Sstevel@tonic-gate #define TIME_MAX LONG_MAX 1017c478bd9Sstevel@tonic-gate 10223c73eccSpwernau #ifndef INSECURE_PERMS 10323c73eccSpwernau #define INSECURE_PERMS(sbuf) (((sbuf).st_uid != 0) || \ 10423c73eccSpwernau ((sbuf).st_mode & S_IRWXG) || ((sbuf).st_mode & S_IRWXO)) 10523c73eccSpwernau #endif 10623c73eccSpwernau 107c7777ac8SPaul Wernau #ifndef PKCS11_TOKSIZE 108c7777ac8SPaul Wernau #define PKCS11_TOKSIZE 32 /* Fixed length of PKCS#11 token string len. */ 109c7777ac8SPaul Wernau #endif 110c7777ac8SPaul Wernau 1119c2c14abSThejaswini Singarajipura /* 1129c2c14abSThejaswini Singarajipura * Solaris UDP port used to communicate with the Solaris Cluster 1139c2c14abSThejaswini Singarajipura * daemon. It is used only when the node is booted in cluster mode. 1149c2c14abSThejaswini Singarajipura */ 1159c2c14abSThejaswini Singarajipura #define CLUSTER_UDP_PORT 2005 1169c2c14abSThejaswini Singarajipura 1177c478bd9Sstevel@tonic-gate /* For keyword-lookup tables */ 1187c478bd9Sstevel@tonic-gate typedef struct keywdtab { 1197c478bd9Sstevel@tonic-gate uint_t kw_tag; 1207c478bd9Sstevel@tonic-gate char *kw_str; 1217c478bd9Sstevel@tonic-gate } keywdtab_t; 1227c478bd9Sstevel@tonic-gate 123a1ba8781SMark Fenwick /* 124a1ba8781SMark Fenwick * These different exit states are designed to give consistant behaviour 125a1ba8781SMark Fenwick * when a program needs to exit because of an error. These exit_types 126a1ba8781SMark Fenwick * are used in macros, defined later in this file, which call ipsecutil_exit(). 127a1ba8781SMark Fenwick * What happens when ipsecutil_exit() may differ if the command was started 128a1ba8781SMark Fenwick * on the command line or via smf(5), See ipsecutil_exit() source for details. 129a1ba8781SMark Fenwick * 130a1ba8781SMark Fenwick * Note: The calling function should decide what "debug mode" is before calling 131a1ba8781SMark Fenwick * ipsecutil_exit() with DEBUG_FATAL. 132a1ba8781SMark Fenwick */ 133e3320f40Smarkfen typedef enum exit_type { 134a1ba8781SMark Fenwick SERVICE_EXIT_OK, /* Exit without error. */ 135a1ba8781SMark Fenwick SERVICE_DEGRADE, /* A hint that service should be degraded. */ 136a1ba8781SMark Fenwick SERVICE_BADPERM, /* A Permission error occured. */ 137a1ba8781SMark Fenwick SERVICE_BADCONF, /* Misconfiguration. */ 138a1ba8781SMark Fenwick SERVICE_MAINTAIN, /* smf(5) to put service in maintenance mode. */ 139a1ba8781SMark Fenwick SERVICE_DISABLE, /* Tell smf(5) to disable me. */ 140a1ba8781SMark Fenwick SERVICE_FATAL, /* Whatever happened is not fixable. */ 141a1ba8781SMark Fenwick SERVICE_RESTART, /* Tell smf(5) to restart the service. */ 142a1ba8781SMark Fenwick DEBUG_FATAL /* Exit in debug mode. */ 143e3320f40Smarkfen } exit_type_t; 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate /* 1467c478bd9Sstevel@tonic-gate * Function Prototypes 1477c478bd9Sstevel@tonic-gate */ 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate /* 1507c478bd9Sstevel@tonic-gate * Print errno and if cmdline or readfile, exit; if interactive reset state 1517c478bd9Sstevel@tonic-gate */ 152e3320f40Smarkfen extern void ipsecutil_exit(exit_type_t, char *, FILE *, const char *fmt, ...); 1537c478bd9Sstevel@tonic-gate extern void bail(char *); 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate /* 156a7485808Smarkfen * Localization macro - Only to be used from usr/src/cmd because Macros 157a7485808Smarkfen * are not expanded in usr/src/lib when message catalogs are built. 1587c478bd9Sstevel@tonic-gate */ 159a7485808Smarkfen #define Bail(s) bail(dgettext(TEXT_DOMAIN, s)) 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate /* 1627c478bd9Sstevel@tonic-gate * Print caller-supplied, variable-arg error message, then exit if cmdline 1637c478bd9Sstevel@tonic-gate * or readfile, or reset state if interactive. 1647c478bd9Sstevel@tonic-gate */ 1657c478bd9Sstevel@tonic-gate extern void bail_msg(char *, ...); 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate /* 1687c478bd9Sstevel@tonic-gate * dump_XXX functions produce ASCII output from the passed in data. 1697c478bd9Sstevel@tonic-gate * 1707c478bd9Sstevel@tonic-gate * Because certain errors need to do this stderr, dump_XXX functions 1717c478bd9Sstevel@tonic-gate * take a FILE pointer. 1727c478bd9Sstevel@tonic-gate */ 1737c478bd9Sstevel@tonic-gate 174bb3ed8dfSpwernau extern int dump_sockaddr(struct sockaddr *, uint8_t, boolean_t, FILE *, 175bb3ed8dfSpwernau boolean_t); 1767c478bd9Sstevel@tonic-gate 177628b0c67SMark Fenwick extern int dump_key(uint8_t *, uint_t, uint_t, FILE *, boolean_t); 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate extern int dump_aalg(uint8_t, FILE *); 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate extern int dump_ealg(uint8_t, FILE *); 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate /* return true if sadb string is printable (based on type), false otherwise */ 1847c478bd9Sstevel@tonic-gate extern boolean_t dump_sadb_idtype(uint8_t, FILE *, int *); 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate /* 1877c478bd9Sstevel@tonic-gate * do_interactive: Enter a mode where commands are read from a file; 1887c478bd9Sstevel@tonic-gate * treat stdin special. infile is the file cmds are read from; 1897c478bd9Sstevel@tonic-gate * promptstring is the string printed to stdout (if the cmds are 1907c478bd9Sstevel@tonic-gate * being read from stdin) to prompt for a new command; parseit is 1917c478bd9Sstevel@tonic-gate * the function to be called to process the command line once it's 1927c478bd9Sstevel@tonic-gate * been read in and broken up into an argv/argc vector. 1937c478bd9Sstevel@tonic-gate */ 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate /* callback function passed in to do_interactive() */ 19625e435e0Spwernau typedef void (*parse_cmdln_fn)(int, char **, char *, boolean_t); 1977c478bd9Sstevel@tonic-gate 198bfe6f8f5SVladimir Kotal extern void do_interactive(FILE *, char *, char *, char *, parse_cmdln_fn, 199bfe6f8f5SVladimir Kotal CplMatchFn *); 200e3320f40Smarkfen 201e3320f40Smarkfen extern uint_t lines_parsed; 202e3320f40Smarkfen extern uint_t lines_added; 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate /* convert a string to an IKE_PRIV_* constant */ 2057c478bd9Sstevel@tonic-gate extern int privstr2num(char *); 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate /* convert a string to a D_* debug flag */ 2087c478bd9Sstevel@tonic-gate extern int dbgstr2num(char *); 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate /* convert a string of debug strings with +|- delimiters to a debug level */ 2117c478bd9Sstevel@tonic-gate extern int parsedbgopts(char *); 2127c478bd9Sstevel@tonic-gate 213a12f8217Spwernau /* 2146221cd42SPaul Wernau * SSL library (OpenSSL) 215a12f8217Spwernau */ 216a12f8217Spwernau #define LIBSSL "libssl.so" 217a12f8217Spwernau 218a12f8217Spwernau void libssl_load(void); 2196221cd42SPaul Wernau 2206221cd42SPaul Wernau /* 2216221cd42SPaul Wernau * crypto library (OpenSSL) 2226221cd42SPaul Wernau */ 2236221cd42SPaul Wernau #define LIBCRYPTO "libcrypto.so" 2246221cd42SPaul Wernau 2256221cd42SPaul Wernau void libcrypto_load(void); 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate /* 2287c478bd9Sstevel@tonic-gate * functions to manipulate the kmcookie-label mapping file 2297c478bd9Sstevel@tonic-gate */ 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate #define KMCFILE "/var/run/ipsec_kmc_map" 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate /* 2347c478bd9Sstevel@tonic-gate * Insert a mapping into the file (if it's not already there), given the 2357c478bd9Sstevel@tonic-gate * new label. Return the assigned cookie, or -1 on error. 2367c478bd9Sstevel@tonic-gate */ 2377c478bd9Sstevel@tonic-gate extern int kmc_insert_mapping(char *); 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate /* 2407c478bd9Sstevel@tonic-gate * Lookup the given cookie and return its corresponding label. Return 2417c478bd9Sstevel@tonic-gate * a pointer to the label on success, NULL on error (or if the label is 2427c478bd9Sstevel@tonic-gate * not found). 2437c478bd9Sstevel@tonic-gate */ 2447c478bd9Sstevel@tonic-gate extern char *kmc_lookup_by_cookie(int); 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate /* 2477c478bd9Sstevel@tonic-gate * These globals are declared for us in ipsec_util.c, since it needs to 2487c478bd9Sstevel@tonic-gate * refer to them also... 2497c478bd9Sstevel@tonic-gate */ 2507c478bd9Sstevel@tonic-gate extern boolean_t nflag; /* Avoid nameservice? */ 2517c478bd9Sstevel@tonic-gate extern boolean_t pflag; /* Paranoid w.r.t. printing keying material? */ 2527c478bd9Sstevel@tonic-gate extern boolean_t interactive; 2537c478bd9Sstevel@tonic-gate extern boolean_t readfile; 2547c478bd9Sstevel@tonic-gate extern uint_t lineno; 2558810c16bSdanmcd extern char numprint[NBUF_SIZE]; 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate /* For error recovery in interactive or read-file mode. */ 2587c478bd9Sstevel@tonic-gate extern jmp_buf env; 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate /* 2617c478bd9Sstevel@tonic-gate * Back-end stuff for getalgby*(). 2627c478bd9Sstevel@tonic-gate */ 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate #define INET_IPSECALGSPATH "/etc/inet/" 2657c478bd9Sstevel@tonic-gate #define INET_IPSECALGSFILE (INET_IPSECALGSPATH "ipsecalgs") 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate /* To preserve packages delimiters in /etc/inet/ipsecalgs */ 2687c478bd9Sstevel@tonic-gate typedef struct ipsecalgs_pkg { 2697c478bd9Sstevel@tonic-gate int alg_num; 2707c478bd9Sstevel@tonic-gate char *pkg_name; 2717c478bd9Sstevel@tonic-gate } ipsecalgs_pkg_t; 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate /* 2747c478bd9Sstevel@tonic-gate * The cached representation of /etc/inet/ipsecalgs is represented by: 2757c478bd9Sstevel@tonic-gate * - A dynamically-grown (optionally sorted) array of IPsec protocols 2767c478bd9Sstevel@tonic-gate * - Each protocol has an array (again, dynamically grown and sorted) 2777c478bd9Sstevel@tonic-gate * of algorithms, each a full-fledged struct ipsecalgent. 2787c478bd9Sstevel@tonic-gate * - The getipsecalg*() routines will search the list, then duplicate the 2797c478bd9Sstevel@tonic-gate * struct ipsecalgent and return it. 2807c478bd9Sstevel@tonic-gate */ 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate typedef enum { 2837c478bd9Sstevel@tonic-gate LIBIPSEC_ALGS_EXEC_SYNC, 2847c478bd9Sstevel@tonic-gate LIBIPSEC_ALGS_EXEC_ASYNC 2857c478bd9Sstevel@tonic-gate } ipsecalgs_exec_mode_t; 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate typedef struct ipsec_proto { 2887c478bd9Sstevel@tonic-gate int proto_num; 2897c478bd9Sstevel@tonic-gate char *proto_name; 2907c478bd9Sstevel@tonic-gate char *proto_pkg; 2917c478bd9Sstevel@tonic-gate int proto_numalgs; 2927c478bd9Sstevel@tonic-gate struct ipsecalgent **proto_algs; 2937c478bd9Sstevel@tonic-gate ipsecalgs_pkg_t *proto_algs_pkgs; 2947c478bd9Sstevel@tonic-gate int proto_algs_npkgs; 2957c478bd9Sstevel@tonic-gate ipsecalgs_exec_mode_t proto_exec_mode; 2967c478bd9Sstevel@tonic-gate } ipsec_proto_t; 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate extern void _build_internal_algs(ipsec_proto_t **, int *); 2997c478bd9Sstevel@tonic-gate extern int _str_to_ipsec_exec_mode(char *, ipsecalgs_exec_mode_t *); 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate extern int addipsecalg(struct ipsecalgent *, uint_t); 3027c478bd9Sstevel@tonic-gate extern int delipsecalgbyname(const char *, int); 3037c478bd9Sstevel@tonic-gate extern int delipsecalgbynum(int, int); 3047c478bd9Sstevel@tonic-gate extern int addipsecproto(const char *, int, ipsecalgs_exec_mode_t, uint_t); 3057c478bd9Sstevel@tonic-gate extern int delipsecprotobyname(const char *); 3067c478bd9Sstevel@tonic-gate extern int delipsecprotobynum(int); 3077c478bd9Sstevel@tonic-gate extern int *getipsecprotos(int *); 3087c478bd9Sstevel@tonic-gate extern int *getipsecalgs(int *, int); 3097c478bd9Sstevel@tonic-gate extern int list_ints(FILE *, int *); 3107c478bd9Sstevel@tonic-gate extern const char *ipsecalgs_diag(int); 3117c478bd9Sstevel@tonic-gate extern int ipsecproto_get_exec_mode(int, ipsecalgs_exec_mode_t *); 3127c478bd9Sstevel@tonic-gate extern int ipsecproto_set_exec_mode(int, ipsecalgs_exec_mode_t); 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate /* Flags for add/delete routines. */ 3157c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_ADD_FORCE 0x00000001 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate /* 3187c478bd9Sstevel@tonic-gate * Helper definitions for indices into array of key sizes when key sizes 3197c478bd9Sstevel@tonic-gate * are defined by range. 3207c478bd9Sstevel@tonic-gate */ 3217c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_KEY_DEF_IDX 0 /* default key size */ 3227c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_KEY_MIN_IDX 1 /* min key size */ 3237c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_KEY_MAX_IDX 2 /* max key size */ 3247c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_KEY_NUM_VAL 4 /* def, min, max, 0 */ 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate /* Error codes for IPsec algorithms management */ 3277c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_DIAG_ALG_EXISTS -1 3287c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_DIAG_PROTO_EXISTS -2 3297c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_DIAG_UNKN_PROTO -3 3307c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_DIAG_UNKN_ALG -4 3317c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_DIAG_NOMEM -5 3327c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_DIAG_ALGSFILEOPEN -6 3337c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_DIAG_ALGSFILEFDOPEN -7 3347c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_DIAG_ALGSFILELOCK -8 3357c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_DIAG_ALGSFILERENAME -9 3367c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_DIAG_ALGSFILEWRITE -10 3377c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_DIAG_ALGSFILECHMOD -11 3387c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_DIAG_ALGSFILECHOWN -12 3397c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_DIAG_ALGSFILECLOSE -13 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate /* /etc/inet/ipsecalgs keywords and package sections delimiters */ 3427c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_LINE_PROTO "PROTO|" 3437c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_LINE_ALG "ALG|" 3447c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_LINE_PKGSTART "# Start " 3457c478bd9Sstevel@tonic-gate #define LIBIPSEC_ALGS_LINE_PKGEND "# End " 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate /* Put these in libnsl for and process caching testing. */ 3487c478bd9Sstevel@tonic-gate extern int *_real_getipsecprotos(int *); 3497c478bd9Sstevel@tonic-gate extern int *_real_getipsecalgs(int *, int); 3507c478bd9Sstevel@tonic-gate extern struct ipsecalgent *_duplicate_alg(struct ipsecalgent *); 3517c478bd9Sstevel@tonic-gate extern void _clean_trash(ipsec_proto_t *, int); 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate /* spdsock support functions */ 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate /* Return values for spdsock_get_ext(). */ 3567c478bd9Sstevel@tonic-gate #define KGE_OK 0 3577c478bd9Sstevel@tonic-gate #define KGE_DUP 1 3587c478bd9Sstevel@tonic-gate #define KGE_UNK 2 3597c478bd9Sstevel@tonic-gate #define KGE_LEN 3 3607c478bd9Sstevel@tonic-gate #define KGE_CHK 4 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate extern int spdsock_get_ext(spd_ext_t *[], spd_msg_t *, uint_t, char *, uint_t); 3637c478bd9Sstevel@tonic-gate extern const char *spdsock_diag(int); 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate /* PF_KEY (keysock) support functions */ 3667c478bd9Sstevel@tonic-gate extern const char *keysock_diag(int); 3678810c16bSdanmcd extern int in_masktoprefix(uint8_t *, boolean_t); 3688810c16bSdanmcd 3698810c16bSdanmcd /* SA support functions */ 3708810c16bSdanmcd 371*510c3f91SVladimir Kotal extern char *secs2out(unsigned int, char *, int, int); 372*510c3f91SVladimir Kotal extern char *secs2str(unsigned int, char *, int); 373*510c3f91SVladimir Kotal extern char *bytecnt2out(uint64_t, char *, size_t, int); 374*510c3f91SVladimir Kotal extern char *bytecnt2str(uint64_t, char *, size_t); 3758810c16bSdanmcd extern void print_diagnostic(FILE *, uint16_t); 376bb3ed8dfSpwernau extern void print_sadb_msg(FILE *, struct sadb_msg *, time_t, boolean_t); 377bb3ed8dfSpwernau extern void print_sa(FILE *, char *, struct sadb_sa *); 378bb3ed8dfSpwernau extern void printsatime(FILE *, int64_t, const char *, const char *, 379bb3ed8dfSpwernau const char *, boolean_t); 380bb3ed8dfSpwernau extern void print_lifetimes(FILE *, time_t, struct sadb_lifetime *, 3819c2c14abSThejaswini Singarajipura struct sadb_lifetime *, struct sadb_lifetime *, struct sadb_lifetime *, 3829c2c14abSThejaswini Singarajipura boolean_t vflag); 383bb3ed8dfSpwernau extern void print_address(FILE *, char *, struct sadb_address *, boolean_t); 384a12f8217Spwernau extern void print_asn1_name(FILE *, const unsigned char *, long); 385bb3ed8dfSpwernau extern void print_key(FILE *, char *, struct sadb_key *); 386bb3ed8dfSpwernau extern void print_ident(FILE *, char *, struct sadb_ident *); 3875d3b8cb7SBill Sommerfeld extern void print_sens(FILE *, char *, const struct sadb_sens *, boolean_t); 388bb3ed8dfSpwernau extern void print_prop(FILE *, char *, struct sadb_prop *); 389bb3ed8dfSpwernau extern void print_eprop(FILE *, char *, struct sadb_prop *); 390bb3ed8dfSpwernau extern void print_supp(FILE *, char *, struct sadb_supported *); 391bb3ed8dfSpwernau extern void print_spirange(FILE *, char *, struct sadb_spirange *); 392bb3ed8dfSpwernau extern void print_kmc(FILE *, char *, struct sadb_x_kmc *); 393bb3ed8dfSpwernau extern void print_samsg(FILE *, uint64_t *, boolean_t, boolean_t, boolean_t); 3948810c16bSdanmcd extern char *rparsesatype(int); 3958810c16bSdanmcd extern char *rparsealg(uint8_t, int); 3968810c16bSdanmcd extern char *rparseidtype(uint16_t); 3978810c16bSdanmcd extern boolean_t save_lifetime(struct sadb_lifetime *, FILE *); 3988810c16bSdanmcd extern boolean_t save_address(struct sadb_address *, FILE *); 3998810c16bSdanmcd extern boolean_t save_key(struct sadb_key *, FILE *); 4008810c16bSdanmcd extern boolean_t save_ident(struct sadb_ident *, FILE *); 4018810c16bSdanmcd extern void save_assoc(uint64_t *, FILE *); 4028810c16bSdanmcd extern FILE *opensavefile(char *); 4038810c16bSdanmcd extern const char *do_inet_ntop(const void *, char *, size_t); 4047c478bd9Sstevel@tonic-gate 405e3320f40Smarkfen /* 4065d3b8cb7SBill Sommerfeld * Label conversion convenience functions. 4075d3b8cb7SBill Sommerfeld */ 4085d3b8cb7SBill Sommerfeld 4095d3b8cb7SBill Sommerfeld #include <tsol/label.h> 4105d3b8cb7SBill Sommerfeld 4115d3b8cb7SBill Sommerfeld extern void ipsec_convert_sens_to_bslabel(const struct sadb_sens *, 4125d3b8cb7SBill Sommerfeld bslabel_t *); 4135d3b8cb7SBill Sommerfeld extern int ipsec_convert_sl_to_sens(int doi, bslabel_t *, struct sadb_sens *); 4145d3b8cb7SBill Sommerfeld extern void ipsec_convert_bslabel_to_string(bslabel_t *, char **); 4155d3b8cb7SBill Sommerfeld extern void ipsec_convert_bslabel_to_hex(bslabel_t *, char **); 4165d3b8cb7SBill Sommerfeld 4175d3b8cb7SBill Sommerfeld /* 418e3320f40Smarkfen * These exit macros give a consistent exit behaviour for all 419e3320f40Smarkfen * programs that use libipsecutil. These wll work in usr/src/cmd 420e3320f40Smarkfen * and usr/src/lib, but because macros in usr/src/lib don't get 421e3320f40Smarkfen * expanded when I18N message catalogs are built, avoid using 422a1ba8781SMark Fenwick * these with text inside libipsecutil. See source of ipsecutil_exit() 423a1ba8781SMark Fenwick * for more details. 424e3320f40Smarkfen */ 425e3320f40Smarkfen #define EXIT_OK(x) \ 426e3320f40Smarkfen ipsecutil_exit(SERVICE_EXIT_OK, my_fmri, debugfile, \ 427e3320f40Smarkfen dgettext(TEXT_DOMAIN, x)) 428e3320f40Smarkfen #define EXIT_OK2(x, y) \ 429e3320f40Smarkfen ipsecutil_exit(SERVICE_EXIT_OK, my_fmri, debugfile, \ 430e3320f40Smarkfen dgettext(TEXT_DOMAIN, x), y) 431e3320f40Smarkfen #define EXIT_OK3(x, y, z) \ 432e3320f40Smarkfen ipsecutil_exit(SERVICE_EXIT_OK, my_fmri, debugfile, \ 433e3320f40Smarkfen dgettext(TEXT_DOMAIN, x), y, z) 434e3320f40Smarkfen #define EXIT_BADCONFIG(x) \ 435e3320f40Smarkfen ipsecutil_exit(SERVICE_BADCONF, my_fmri, debugfile, \ 436e3320f40Smarkfen dgettext(TEXT_DOMAIN, x)) 437e3320f40Smarkfen #define EXIT_BADCONFIG2(x, y) \ 438e3320f40Smarkfen ipsecutil_exit(SERVICE_BADCONF, my_fmri, debugfile, \ 439e3320f40Smarkfen dgettext(TEXT_DOMAIN, x), y) 440e3320f40Smarkfen #define EXIT_BADCONFIG3(x, y, z) \ 441e3320f40Smarkfen ipsecutil_exit(SERVICE_BADCONF, my_fmri, debugfile, \ 442e3320f40Smarkfen dgettext(TEXT_DOMAIN, x), y, z) 443e3320f40Smarkfen #define EXIT_MAINTAIN(x) \ 444e3320f40Smarkfen ipsecutil_exit(SERVICE_MAINTAIN, my_fmri, debugfile, \ 445e3320f40Smarkfen dgettext(TEXT_DOMAIN, x)) 446e3320f40Smarkfen #define EXIT_MAINTAIN2(x, y) \ 447e3320f40Smarkfen ipsecutil_exit(SERVICE_MAINTAIN, my_fmri, debugfile, \ 448e3320f40Smarkfen dgettext(TEXT_DOMAIN, x), y) 449e3320f40Smarkfen #define EXIT_DEGRADE(x) \ 450e3320f40Smarkfen ipsecutil_exit(SERVICE_DEGRADE, my_fmri, debugfile, \ 451e3320f40Smarkfen dgettext(TEXT_DOMAIN, x)) 452e3320f40Smarkfen #define EXIT_BADPERM(x) \ 453e3320f40Smarkfen ipsecutil_exit(SERVICE_BADPERM, my_fmri, debugfile, \ 454e3320f40Smarkfen dgettext(TEXT_DOMAIN, x)) 455e3320f40Smarkfen #define EXIT_BADPERM2(x, y) \ 456e3320f40Smarkfen ipsecutil_exit(SERVICE_BADPERM, my_fmri, debugfile, \ 457e3320f40Smarkfen dgettext(TEXT_DOMAIN, x), y) 458e3320f40Smarkfen #define EXIT_FATAL(x) \ 459e3320f40Smarkfen ipsecutil_exit(SERVICE_FATAL, my_fmri, debugfile, \ 460e3320f40Smarkfen dgettext(TEXT_DOMAIN, x)) 461e3320f40Smarkfen #define EXIT_FATAL2(x, y) \ 462e3320f40Smarkfen ipsecutil_exit(SERVICE_FATAL, my_fmri, debugfile, \ 463e3320f40Smarkfen dgettext(TEXT_DOMAIN, x), y) 464e3320f40Smarkfen #define EXIT_FATAL3(x, y, z) \ 465e3320f40Smarkfen ipsecutil_exit(SERVICE_FATAL, my_fmri, debugfile, \ 466e3320f40Smarkfen dgettext(TEXT_DOMAIN, x), y, z) 467e3320f40Smarkfen #define EXIT_RESTART(x) \ 468e3320f40Smarkfen ipsecutil_exit(SERVICE_RESTART, my_fmri, debugfile, \ 469e3320f40Smarkfen dgettext(TEXT_DOMAIN, x)) 470e3320f40Smarkfen 4717c478bd9Sstevel@tonic-gate #ifdef __cplusplus 4727c478bd9Sstevel@tonic-gate } 4737c478bd9Sstevel@tonic-gate #endif 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate #endif /* _IPSEC_UTIL_H */ 476