6 * Common Development and Distribution License (the "License").
7 * You may not use this file except in compliance with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2012 Milan Juri. All rights reserved.
26 */
27
28 #include <unistd.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <stdarg.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <sys/sysconf.h>
36 #include <strings.h>
37 #include <ctype.h>
38 #include <errno.h>
39 #include <sys/socket.h>
40 #include <netdb.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
43 #include <net/pfkeyv2.h>
44 #include <net/pfpolicy.h>
45 #include <libintl.h>
1135 rtnerr = errno;
1136 goto error;
1137 }
1138 }
1139 (void) fclose(map);
1140
1141 return (rtn_cookie);
1142
1143 error:
1144 (void) fclose(map);
1145 errno = rtnerr;
1146 return (-1);
1147 }
1148
1149 /*
1150 * Lookup the given cookie and return its corresponding label. Return
1151 * a pointer to the label on success, NULL on error (or if the label is
1152 * not found). Note that the returned label pointer points to a static
1153 * string, so the label will be overwritten by a subsequent call to the
1154 * function; the function is also not thread-safe as a result.
1155 */
1156 char *
1157 kmc_lookup_by_cookie(int cookie)
1158 {
1159 FILE *map;
1160 static char linebuf[IBUF_SIZE];
1161 char *cur_label;
1162 int cur_cookie;
1163
1164 if ((map = kmc_open_and_lock(KMCFILE)) == NULL) {
1165 return (NULL);
1166 }
1167
1168 while (fgets(linebuf, sizeof (linebuf), map) != NULL) {
1169
1170 if (kmc_parse_line(linebuf, &cur_cookie, &cur_label) < 0) {
1171 (void) fclose(map);
1172 return (NULL);
1173 }
1174
2574 * Print an SADB_EXT_SPIRANGE extension.
2575 */
2576 void
2577 print_spirange(FILE *file, char *prefix, struct sadb_spirange *range)
2578 {
2579 (void) fprintf(file, dgettext(TEXT_DOMAIN,
2580 "%sSPI Range, min=0x%x, max=0x%x\n"), prefix,
2581 htonl(range->sadb_spirange_min),
2582 htonl(range->sadb_spirange_max));
2583 }
2584
2585 /*
2586 * Print an SADB_X_EXT_KM_COOKIE extension.
2587 */
2588
2589 void
2590 print_kmc(FILE *file, char *prefix, struct sadb_x_kmc *kmc)
2591 {
2592 char *cookie_label;
2593
2594 if ((cookie_label = kmc_lookup_by_cookie(kmc->sadb_x_kmc_cookie)) ==
2595 NULL)
2596 cookie_label = dgettext(TEXT_DOMAIN, "<Label not found.>");
2597
2598 (void) fprintf(file, dgettext(TEXT_DOMAIN,
2599 "%sProtocol %u, cookie=\"%s\" (%u)\n"), prefix,
2600 kmc->sadb_x_kmc_proto, cookie_label, kmc->sadb_x_kmc_cookie);
2601 }
2602
2603 /*
2604 * Print an SADB_X_EXT_REPLAY_CTR extension.
2605 */
2606
2607 void
2608 print_replay(FILE *file, char *prefix, sadb_x_replay_ctr_t *repl)
2609 {
2610 (void) fprintf(file, dgettext(TEXT_DOMAIN,
2611 "%sReplay Value "), prefix);
2612 if ((repl->sadb_x_rc_replay32 == 0) &&
2613 (repl->sadb_x_rc_replay64 == 0)) {
2614 (void) fprintf(file, dgettext(TEXT_DOMAIN,
2615 "<Value not found.>"));
2616 }
2617 /*
2618 * We currently do not support a 64-bit replay value.
2619 * RFC 4301 will require one, however, and we have a field
2620 * in place when 4301 is built.
|
6 * Common Development and Distribution License (the "License").
7 * You may not use this file except in compliance with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2012 Milan Juri. All rights reserved.
26 * Copyright 2017 Joyent, Inc.
27 */
28
29 #include <unistd.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <stdarg.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <sys/sysconf.h>
37 #include <strings.h>
38 #include <ctype.h>
39 #include <errno.h>
40 #include <sys/socket.h>
41 #include <netdb.h>
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
44 #include <net/pfkeyv2.h>
45 #include <net/pfpolicy.h>
46 #include <libintl.h>
1136 rtnerr = errno;
1137 goto error;
1138 }
1139 }
1140 (void) fclose(map);
1141
1142 return (rtn_cookie);
1143
1144 error:
1145 (void) fclose(map);
1146 errno = rtnerr;
1147 return (-1);
1148 }
1149
1150 /*
1151 * Lookup the given cookie and return its corresponding label. Return
1152 * a pointer to the label on success, NULL on error (or if the label is
1153 * not found). Note that the returned label pointer points to a static
1154 * string, so the label will be overwritten by a subsequent call to the
1155 * function; the function is also not thread-safe as a result.
1156 *
1157 * Because this is possibly publically exported, do not change its name,
1158 * but this is for all intents and purposes an IKEv1/in.iked function.
1159 */
1160 char *
1161 kmc_lookup_by_cookie(int cookie)
1162 {
1163 FILE *map;
1164 static char linebuf[IBUF_SIZE];
1165 char *cur_label;
1166 int cur_cookie;
1167
1168 if ((map = kmc_open_and_lock(KMCFILE)) == NULL) {
1169 return (NULL);
1170 }
1171
1172 while (fgets(linebuf, sizeof (linebuf), map) != NULL) {
1173
1174 if (kmc_parse_line(linebuf, &cur_cookie, &cur_label) < 0) {
1175 (void) fclose(map);
1176 return (NULL);
1177 }
1178
2578 * Print an SADB_EXT_SPIRANGE extension.
2579 */
2580 void
2581 print_spirange(FILE *file, char *prefix, struct sadb_spirange *range)
2582 {
2583 (void) fprintf(file, dgettext(TEXT_DOMAIN,
2584 "%sSPI Range, min=0x%x, max=0x%x\n"), prefix,
2585 htonl(range->sadb_spirange_min),
2586 htonl(range->sadb_spirange_max));
2587 }
2588
2589 /*
2590 * Print an SADB_X_EXT_KM_COOKIE extension.
2591 */
2592
2593 void
2594 print_kmc(FILE *file, char *prefix, struct sadb_x_kmc *kmc)
2595 {
2596 char *cookie_label;
2597
2598 switch (kmc->sadb_x_kmc_proto) {
2599 case SADB_X_KMP_IKE:
2600 cookie_label = kmc_lookup_by_cookie(kmc->sadb_x_kmc_cookie);
2601 if (cookie_label == NULL)
2602 cookie_label =
2603 dgettext(TEXT_DOMAIN, "<Label not found.>");
2604 (void) fprintf(file, dgettext(TEXT_DOMAIN,
2605 "%sProtocol %u, cookie=\"%s\" (%u)\n"), prefix,
2606 kmc->sadb_x_kmc_proto, cookie_label,
2607 kmc->sadb_x_kmc_cookie);
2608 return;
2609 case SADB_X_KMP_MANUAL:
2610 cookie_label = dgettext(TEXT_DOMAIN, "Manual SA with cookie");
2611 break;
2612 /* case SADB_X_KMP_IKEV2: */
2613 default:
2614 cookie_label =
2615 dgettext(TEXT_DOMAIN, "<unknown KM protocol>");
2616 break;
2617 }
2618
2619 /* XXX KEBE ASKS... htonll() on generic kmc_cookie? */
2620 (void) fprintf(file, dgettext(TEXT_DOMAIN,
2621 "%sProtocol %u, cookie=\"%s\" (0x%"PRIx64"/%"PRIu64")\n"),
2622 prefix, kmc->sadb_x_kmc_proto, cookie_label,
2623 kmc->sadb_x_kmc_cookie64, kmc->sadb_x_kmc_cookie64);
2624 }
2625
2626 /*
2627 * Print an SADB_X_EXT_REPLAY_CTR extension.
2628 */
2629
2630 void
2631 print_replay(FILE *file, char *prefix, sadb_x_replay_ctr_t *repl)
2632 {
2633 (void) fprintf(file, dgettext(TEXT_DOMAIN,
2634 "%sReplay Value "), prefix);
2635 if ((repl->sadb_x_rc_replay32 == 0) &&
2636 (repl->sadb_x_rc_replay64 == 0)) {
2637 (void) fprintf(file, dgettext(TEXT_DOMAIN,
2638 "<Value not found.>"));
2639 }
2640 /*
2641 * We currently do not support a 64-bit replay value.
2642 * RFC 4301 will require one, however, and we have a field
2643 * in place when 4301 is built.
|