Print this page
8927 sadb_x_kmc_t's KM cookie should be 64-bits
Reviewed by: Jason King <jason.king@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Yuri Pankov <yuripv@gmx.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/lib/libipsecutil/common/ipsec_util.h
+++ new/usr/src/lib/libipsecutil/common/ipsec_util.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 +/*
26 + * Copyright 2017 Joyent, Inc.
27 + */
25 28
26 29 #ifndef _IPSEC_UTIL_H
27 30 #define _IPSEC_UTIL_H
28 31
29 32 /*
30 33 * Headers and definitions for support functions that are shared by
31 34 * the ipsec utilities ipseckey and ikeadm.
32 35 */
33 36
34 37 #ifdef __cplusplus
35 38 extern "C" {
36 39 #endif
37 40
38 41 #include <sys/types.h>
39 42 #include <sys/socket.h>
40 43 #include <net/pfkeyv2.h>
41 44 #include <netinet/in.h>
42 45 #include <inet/ip.h>
43 46 #include <setjmp.h>
44 47 #include <stdio.h>
45 48 #include <err.h>
46 49 #include <errfp.h>
47 50 #include <net/pfpolicy.h>
48 51 #include <libtecla.h>
49 52
50 53 #ifndef A_CNT
51 54 /* macros for array manipulation */
52 55 #define A_CNT(arr) (sizeof (arr)/sizeof (arr[0]))
53 56 #define A_END(arr) (&arr[A_CNT(arr)])
54 57 #endif
55 58
56 59 /* used for file parsing */
57 60 #define NBUF_SIZE 16
58 61 #define COMMENT_CHAR '#'
59 62 #define CONT_CHAR '\\'
60 63 #define QUOTE_CHAR '"'
61 64 /*
62 65 * Input buffer size limits maximum line length for both file parsing and
63 66 * interactive mode. 4K chars should be enough even for broad commands and
64 67 * all possible key lenghts of today's symmetric ciphers entered via
65 68 * ipseckey(1M) which has the most bifurcated grammar from all IPsec commands.
66 69 */
67 70 #define IBUF_SIZE 4096
68 71
69 72 /* used for command-line parsing */
70 73 #define START_ARG 8
71 74 #define TOO_MANY_ARGS (START_ARG << 9)
72 75
73 76 /* Return codes for argv/argc vector creation */
74 77 #define TOO_MANY_TOKENS -3
75 78 #define MEMORY_ALLOCATION -2
76 79 #define COMMENT_LINE 1
77 80 #define SUCCESS 0
78 81
79 82 /* Flags for {bytecnt,secs}2out() */
80 83 #define SPC_NOSPACES 0x00000000 /* no space prefix/suffix */
81 84 #define SPC_BEGIN 0x00000001 /* put space at the beginning */
82 85 #define SPC_END 0x00000002 /* put space at the end */
83 86 #define SPC_BOTH SPC_BEGIN|SPC_END /* print both spaces */
84 87
85 88 /*
86 89 * The following lengths should be sufficient for character buffers passed to
87 90 * bytecnt2str(),secs2str(). This is because the string output of these
88 91 * functions consists of limited number and units. The lengths should be also
89 92 * sufficient for bytecnt2out(),secs2out() functions.
90 93 */
91 94 #define BYTE_STR_SIZE 16
92 95 #define SECS_STR_SIZE 20
93 96
94 97 /*
95 98 * Time printing defines...
96 99 *
97 100 * TBUF_SIZE is pretty arbitrary. Perhaps it shouldn't be.
98 101 */
99 102 #define TBUF_SIZE 50
100 103 #define TIME_MAX LONG_MAX
101 104
102 105 #ifndef INSECURE_PERMS
103 106 #define INSECURE_PERMS(sbuf) (((sbuf).st_uid != 0) || \
104 107 ((sbuf).st_mode & S_IRWXG) || ((sbuf).st_mode & S_IRWXO))
105 108 #endif
106 109
107 110 #ifndef PKCS11_TOKSIZE
108 111 #define PKCS11_TOKSIZE 32 /* Fixed length of PKCS#11 token string len. */
109 112 #endif
110 113
111 114 /*
112 115 * Solaris UDP port used to communicate with the Solaris Cluster
113 116 * daemon. It is used only when the node is booted in cluster mode.
114 117 */
115 118 #define CLUSTER_UDP_PORT 2005
116 119
117 120 /* For keyword-lookup tables */
118 121 typedef struct keywdtab {
119 122 uint_t kw_tag;
120 123 char *kw_str;
121 124 } keywdtab_t;
122 125
123 126 /*
124 127 * These different exit states are designed to give consistant behaviour
125 128 * when a program needs to exit because of an error. These exit_types
126 129 * are used in macros, defined later in this file, which call ipsecutil_exit().
127 130 * What happens when ipsecutil_exit() may differ if the command was started
128 131 * on the command line or via smf(5), See ipsecutil_exit() source for details.
129 132 *
130 133 * Note: The calling function should decide what "debug mode" is before calling
131 134 * ipsecutil_exit() with DEBUG_FATAL.
132 135 */
133 136 typedef enum exit_type {
134 137 SERVICE_EXIT_OK, /* Exit without error. */
135 138 SERVICE_DEGRADE, /* A hint that service should be degraded. */
136 139 SERVICE_BADPERM, /* A Permission error occured. */
137 140 SERVICE_BADCONF, /* Misconfiguration. */
138 141 SERVICE_MAINTAIN, /* smf(5) to put service in maintenance mode. */
139 142 SERVICE_DISABLE, /* Tell smf(5) to disable me. */
140 143 SERVICE_FATAL, /* Whatever happened is not fixable. */
141 144 SERVICE_RESTART, /* Tell smf(5) to restart the service. */
142 145 DEBUG_FATAL /* Exit in debug mode. */
143 146 } exit_type_t;
144 147
145 148 /*
146 149 * Function Prototypes
147 150 */
148 151
149 152 /*
150 153 * Print errno and if cmdline or readfile, exit; if interactive reset state
151 154 */
152 155 extern void ipsecutil_exit(exit_type_t, char *, FILE *, const char *fmt, ...);
153 156 extern void bail(char *);
154 157
155 158 /*
156 159 * Localization macro - Only to be used from usr/src/cmd because Macros
157 160 * are not expanded in usr/src/lib when message catalogs are built.
158 161 */
159 162 #define Bail(s) bail(dgettext(TEXT_DOMAIN, s))
160 163
161 164 /*
162 165 * Print caller-supplied, variable-arg error message, then exit if cmdline
163 166 * or readfile, or reset state if interactive.
164 167 */
165 168 extern void bail_msg(char *, ...);
166 169
167 170 /*
168 171 * dump_XXX functions produce ASCII output from the passed in data.
169 172 *
170 173 * Because certain errors need to do this stderr, dump_XXX functions
171 174 * take a FILE pointer.
172 175 */
173 176
174 177 extern int dump_sockaddr(struct sockaddr *, uint8_t, boolean_t, FILE *,
175 178 boolean_t);
176 179
177 180 extern int dump_key(uint8_t *, uint_t, uint_t, FILE *, boolean_t);
178 181
179 182 extern int dump_aalg(uint8_t, FILE *);
180 183
181 184 extern int dump_ealg(uint8_t, FILE *);
182 185
183 186 /* return true if sadb string is printable (based on type), false otherwise */
184 187 extern boolean_t dump_sadb_idtype(uint8_t, FILE *, int *);
185 188
186 189 /*
187 190 * do_interactive: Enter a mode where commands are read from a file;
188 191 * treat stdin special. infile is the file cmds are read from;
189 192 * promptstring is the string printed to stdout (if the cmds are
190 193 * being read from stdin) to prompt for a new command; parseit is
191 194 * the function to be called to process the command line once it's
192 195 * been read in and broken up into an argv/argc vector.
193 196 */
194 197
195 198 /* callback function passed in to do_interactive() */
196 199 typedef void (*parse_cmdln_fn)(int, char **, char *, boolean_t);
197 200
198 201 extern void do_interactive(FILE *, char *, char *, char *, parse_cmdln_fn,
199 202 CplMatchFn *);
200 203
201 204 extern uint_t lines_parsed;
202 205 extern uint_t lines_added;
203 206
204 207 /* convert a string to an IKE_PRIV_* constant */
205 208 extern int privstr2num(char *);
206 209
207 210 /* convert a string to a D_* debug flag */
208 211 extern int dbgstr2num(char *);
209 212
210 213 /* convert a string of debug strings with +|- delimiters to a debug level */
211 214 extern int parsedbgopts(char *);
212 215
213 216 /*
214 217 * SSL library (OpenSSL)
215 218 */
216 219 #define LIBSSL "libssl.so"
217 220
|
↓ open down ↓ |
183 lines elided |
↑ open up ↑ |
218 221 void libssl_load(void);
219 222
220 223 /*
221 224 * crypto library (OpenSSL)
222 225 */
223 226 #define LIBCRYPTO "libcrypto.so"
224 227
225 228 void libcrypto_load(void);
226 229
227 230 /*
228 - * functions to manipulate the kmcookie-label mapping file
231 + * functions to manipulate the IKEv1 kmcookie-label mapping file
229 232 */
230 233
231 234 #define KMCFILE "/var/run/ipsec_kmc_map"
232 235
233 236 /*
234 237 * Insert a mapping into the file (if it's not already there), given the
235 238 * new label. Return the assigned cookie, or -1 on error.
236 239 */
237 240 extern int kmc_insert_mapping(char *);
238 241
239 242 /*
240 243 * Lookup the given cookie and return its corresponding label. Return
241 244 * a pointer to the label on success, NULL on error (or if the label is
242 245 * not found).
243 246 */
244 247 extern char *kmc_lookup_by_cookie(int);
245 248
246 249 /*
247 250 * These globals are declared for us in ipsec_util.c, since it needs to
248 251 * refer to them also...
249 252 */
250 253 extern boolean_t nflag; /* Avoid nameservice? */
251 254 extern boolean_t pflag; /* Paranoid w.r.t. printing keying material? */
252 255 extern boolean_t interactive;
253 256 extern boolean_t readfile;
254 257 extern uint_t lineno;
255 258 extern char numprint[NBUF_SIZE];
256 259
257 260 /* For error recovery in interactive or read-file mode. */
258 261 extern jmp_buf env;
259 262
260 263 /*
261 264 * Back-end stuff for getalgby*().
262 265 */
263 266
264 267 #define INET_IPSECALGSPATH "/etc/inet/"
265 268 #define INET_IPSECALGSFILE (INET_IPSECALGSPATH "ipsecalgs")
266 269
267 270 /* To preserve packages delimiters in /etc/inet/ipsecalgs */
268 271 typedef struct ipsecalgs_pkg {
269 272 int alg_num;
270 273 char *pkg_name;
271 274 } ipsecalgs_pkg_t;
272 275
273 276 /*
274 277 * The cached representation of /etc/inet/ipsecalgs is represented by:
275 278 * - A dynamically-grown (optionally sorted) array of IPsec protocols
276 279 * - Each protocol has an array (again, dynamically grown and sorted)
277 280 * of algorithms, each a full-fledged struct ipsecalgent.
278 281 * - The getipsecalg*() routines will search the list, then duplicate the
279 282 * struct ipsecalgent and return it.
280 283 */
281 284
282 285 typedef enum {
283 286 LIBIPSEC_ALGS_EXEC_SYNC,
284 287 LIBIPSEC_ALGS_EXEC_ASYNC
285 288 } ipsecalgs_exec_mode_t;
286 289
287 290 typedef struct ipsec_proto {
288 291 int proto_num;
289 292 char *proto_name;
290 293 char *proto_pkg;
291 294 int proto_numalgs;
292 295 struct ipsecalgent **proto_algs;
293 296 ipsecalgs_pkg_t *proto_algs_pkgs;
294 297 int proto_algs_npkgs;
295 298 ipsecalgs_exec_mode_t proto_exec_mode;
296 299 } ipsec_proto_t;
297 300
298 301 extern void _build_internal_algs(ipsec_proto_t **, int *);
299 302 extern int _str_to_ipsec_exec_mode(char *, ipsecalgs_exec_mode_t *);
300 303
301 304 extern int addipsecalg(struct ipsecalgent *, uint_t);
302 305 extern int delipsecalgbyname(const char *, int);
303 306 extern int delipsecalgbynum(int, int);
304 307 extern int addipsecproto(const char *, int, ipsecalgs_exec_mode_t, uint_t);
305 308 extern int delipsecprotobyname(const char *);
306 309 extern int delipsecprotobynum(int);
307 310 extern int *getipsecprotos(int *);
308 311 extern int *getipsecalgs(int *, int);
309 312 extern int list_ints(FILE *, int *);
310 313 extern const char *ipsecalgs_diag(int);
311 314 extern int ipsecproto_get_exec_mode(int, ipsecalgs_exec_mode_t *);
312 315 extern int ipsecproto_set_exec_mode(int, ipsecalgs_exec_mode_t);
313 316
314 317 /* Flags for add/delete routines. */
315 318 #define LIBIPSEC_ALGS_ADD_FORCE 0x00000001
316 319
317 320 /*
318 321 * Helper definitions for indices into array of key sizes when key sizes
319 322 * are defined by range.
320 323 */
321 324 #define LIBIPSEC_ALGS_KEY_DEF_IDX 0 /* default key size */
322 325 #define LIBIPSEC_ALGS_KEY_MIN_IDX 1 /* min key size */
323 326 #define LIBIPSEC_ALGS_KEY_MAX_IDX 2 /* max key size */
324 327 #define LIBIPSEC_ALGS_KEY_NUM_VAL 4 /* def, min, max, 0 */
325 328
326 329 /* Error codes for IPsec algorithms management */
327 330 #define LIBIPSEC_ALGS_DIAG_ALG_EXISTS -1
328 331 #define LIBIPSEC_ALGS_DIAG_PROTO_EXISTS -2
329 332 #define LIBIPSEC_ALGS_DIAG_UNKN_PROTO -3
330 333 #define LIBIPSEC_ALGS_DIAG_UNKN_ALG -4
331 334 #define LIBIPSEC_ALGS_DIAG_NOMEM -5
332 335 #define LIBIPSEC_ALGS_DIAG_ALGSFILEOPEN -6
333 336 #define LIBIPSEC_ALGS_DIAG_ALGSFILEFDOPEN -7
334 337 #define LIBIPSEC_ALGS_DIAG_ALGSFILELOCK -8
335 338 #define LIBIPSEC_ALGS_DIAG_ALGSFILERENAME -9
336 339 #define LIBIPSEC_ALGS_DIAG_ALGSFILEWRITE -10
337 340 #define LIBIPSEC_ALGS_DIAG_ALGSFILECHMOD -11
338 341 #define LIBIPSEC_ALGS_DIAG_ALGSFILECHOWN -12
339 342 #define LIBIPSEC_ALGS_DIAG_ALGSFILECLOSE -13
340 343
341 344 /* /etc/inet/ipsecalgs keywords and package sections delimiters */
342 345 #define LIBIPSEC_ALGS_LINE_PROTO "PROTO|"
343 346 #define LIBIPSEC_ALGS_LINE_ALG "ALG|"
344 347 #define LIBIPSEC_ALGS_LINE_PKGSTART "# Start "
345 348 #define LIBIPSEC_ALGS_LINE_PKGEND "# End "
346 349
347 350 /* Put these in libnsl for and process caching testing. */
348 351 extern int *_real_getipsecprotos(int *);
349 352 extern int *_real_getipsecalgs(int *, int);
350 353 extern struct ipsecalgent *_duplicate_alg(struct ipsecalgent *);
351 354 extern void _clean_trash(ipsec_proto_t *, int);
352 355
353 356 /* spdsock support functions */
354 357
355 358 /* Return values for spdsock_get_ext(). */
356 359 #define KGE_OK 0
357 360 #define KGE_DUP 1
358 361 #define KGE_UNK 2
359 362 #define KGE_LEN 3
360 363 #define KGE_CHK 4
361 364
362 365 extern int spdsock_get_ext(spd_ext_t *[], spd_msg_t *, uint_t, char *, uint_t);
363 366 extern const char *spdsock_diag(int);
364 367
365 368 /* PF_KEY (keysock) support functions */
366 369 extern const char *keysock_diag(int);
367 370 extern int in_masktoprefix(uint8_t *, boolean_t);
368 371
369 372 /* SA support functions */
370 373
371 374 extern char *secs2out(unsigned int, char *, int, int);
372 375 extern char *secs2str(unsigned int, char *, int);
373 376 extern char *bytecnt2out(uint64_t, char *, size_t, int);
374 377 extern char *bytecnt2str(uint64_t, char *, size_t);
375 378 extern void print_diagnostic(FILE *, uint16_t);
376 379 extern void print_sadb_msg(FILE *, struct sadb_msg *, time_t, boolean_t);
377 380 extern void print_sa(FILE *, char *, struct sadb_sa *);
378 381 extern void printsatime(FILE *, int64_t, const char *, const char *,
379 382 const char *, boolean_t);
380 383 extern void print_lifetimes(FILE *, time_t, struct sadb_lifetime *,
381 384 struct sadb_lifetime *, struct sadb_lifetime *, struct sadb_lifetime *,
382 385 boolean_t vflag);
383 386 extern void print_address(FILE *, char *, struct sadb_address *, boolean_t);
384 387 extern void print_asn1_name(FILE *, const unsigned char *, long);
385 388 extern void print_key(FILE *, char *, struct sadb_key *);
386 389 extern void print_ident(FILE *, char *, struct sadb_ident *);
387 390 extern void print_sens(FILE *, char *, const struct sadb_sens *, boolean_t);
388 391 extern void print_prop(FILE *, char *, struct sadb_prop *);
389 392 extern void print_eprop(FILE *, char *, struct sadb_prop *);
390 393 extern void print_supp(FILE *, char *, struct sadb_supported *);
391 394 extern void print_spirange(FILE *, char *, struct sadb_spirange *);
392 395 extern void print_kmc(FILE *, char *, struct sadb_x_kmc *);
393 396 extern void print_samsg(FILE *, uint64_t *, boolean_t, boolean_t, boolean_t);
394 397 extern char *rparsesatype(int);
395 398 extern char *rparsealg(uint8_t, int);
396 399 extern char *rparseidtype(uint16_t);
397 400 extern boolean_t save_lifetime(struct sadb_lifetime *, FILE *);
398 401 extern boolean_t save_address(struct sadb_address *, FILE *);
399 402 extern boolean_t save_key(struct sadb_key *, FILE *);
400 403 extern boolean_t save_ident(struct sadb_ident *, FILE *);
401 404 extern void save_assoc(uint64_t *, FILE *);
402 405 extern FILE *opensavefile(char *);
403 406 extern const char *do_inet_ntop(const void *, char *, size_t);
404 407
405 408 /*
406 409 * Label conversion convenience functions.
407 410 */
408 411
409 412 #include <tsol/label.h>
410 413
411 414 extern void ipsec_convert_sens_to_bslabel(const struct sadb_sens *,
412 415 bslabel_t *);
413 416 extern int ipsec_convert_sl_to_sens(int doi, bslabel_t *, struct sadb_sens *);
414 417 extern void ipsec_convert_bslabel_to_string(bslabel_t *, char **);
415 418 extern void ipsec_convert_bslabel_to_hex(bslabel_t *, char **);
416 419
417 420 /*
418 421 * These exit macros give a consistent exit behaviour for all
419 422 * programs that use libipsecutil. These wll work in usr/src/cmd
420 423 * and usr/src/lib, but because macros in usr/src/lib don't get
421 424 * expanded when I18N message catalogs are built, avoid using
422 425 * these with text inside libipsecutil. See source of ipsecutil_exit()
423 426 * for more details.
424 427 */
425 428 #define EXIT_OK(x) \
426 429 ipsecutil_exit(SERVICE_EXIT_OK, my_fmri, debugfile, \
427 430 dgettext(TEXT_DOMAIN, x))
428 431 #define EXIT_OK2(x, y) \
429 432 ipsecutil_exit(SERVICE_EXIT_OK, my_fmri, debugfile, \
430 433 dgettext(TEXT_DOMAIN, x), y)
431 434 #define EXIT_OK3(x, y, z) \
432 435 ipsecutil_exit(SERVICE_EXIT_OK, my_fmri, debugfile, \
433 436 dgettext(TEXT_DOMAIN, x), y, z)
434 437 #define EXIT_BADCONFIG(x) \
435 438 ipsecutil_exit(SERVICE_BADCONF, my_fmri, debugfile, \
436 439 dgettext(TEXT_DOMAIN, x))
437 440 #define EXIT_BADCONFIG2(x, y) \
438 441 ipsecutil_exit(SERVICE_BADCONF, my_fmri, debugfile, \
439 442 dgettext(TEXT_DOMAIN, x), y)
440 443 #define EXIT_BADCONFIG3(x, y, z) \
441 444 ipsecutil_exit(SERVICE_BADCONF, my_fmri, debugfile, \
442 445 dgettext(TEXT_DOMAIN, x), y, z)
443 446 #define EXIT_MAINTAIN(x) \
444 447 ipsecutil_exit(SERVICE_MAINTAIN, my_fmri, debugfile, \
445 448 dgettext(TEXT_DOMAIN, x))
446 449 #define EXIT_MAINTAIN2(x, y) \
447 450 ipsecutil_exit(SERVICE_MAINTAIN, my_fmri, debugfile, \
448 451 dgettext(TEXT_DOMAIN, x), y)
449 452 #define EXIT_DEGRADE(x) \
450 453 ipsecutil_exit(SERVICE_DEGRADE, my_fmri, debugfile, \
451 454 dgettext(TEXT_DOMAIN, x))
452 455 #define EXIT_BADPERM(x) \
453 456 ipsecutil_exit(SERVICE_BADPERM, my_fmri, debugfile, \
454 457 dgettext(TEXT_DOMAIN, x))
455 458 #define EXIT_BADPERM2(x, y) \
456 459 ipsecutil_exit(SERVICE_BADPERM, my_fmri, debugfile, \
457 460 dgettext(TEXT_DOMAIN, x), y)
458 461 #define EXIT_FATAL(x) \
459 462 ipsecutil_exit(SERVICE_FATAL, my_fmri, debugfile, \
460 463 dgettext(TEXT_DOMAIN, x))
461 464 #define EXIT_FATAL2(x, y) \
462 465 ipsecutil_exit(SERVICE_FATAL, my_fmri, debugfile, \
463 466 dgettext(TEXT_DOMAIN, x), y)
464 467 #define EXIT_FATAL3(x, y, z) \
465 468 ipsecutil_exit(SERVICE_FATAL, my_fmri, debugfile, \
466 469 dgettext(TEXT_DOMAIN, x), y, z)
467 470 #define EXIT_RESTART(x) \
468 471 ipsecutil_exit(SERVICE_RESTART, my_fmri, debugfile, \
469 472 dgettext(TEXT_DOMAIN, x))
470 473
471 474 #ifdef __cplusplus
472 475 }
473 476 #endif
474 477
475 478 #endif /* _IPSEC_UTIL_H */
|
↓ open down ↓ |
237 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX