4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * tninfo.c - Trusted network reporting utility
30 #include <sys/types.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
40 #include <tsol/label.h>
43 static void usage(void);
44 static int print_rhtp(const char *);
45 static int print_rh(const char *);
46 static int print_mlp(const char *);
49 main(int argc
, char *argv
[])
52 int ret
= 0; /* return code */
54 /* set the locale for only the messages system (all else is clean) */
55 (void) setlocale(LC_ALL
, "");
56 #ifndef TEXT_DOMAIN /* Should be defined by cc -D */
57 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
60 (void) textdomain(TEXT_DOMAIN
);
65 while ((chr
= getopt(argc
, argv
, "h:m:t:")) != EOF
) {
68 ret
|= print_rh(optarg
);
71 ret
|= print_mlp(optarg
);
74 ret
|= print_rhtp(optarg
);
87 (void) fprintf(stderr
, gettext("usage: tninfo [-h host_name] "
88 "[-m zone_name] [-t template_name]\n"));
93 l_to_str(const m_label_t
*l
, char **str
, int ltype
)
95 if (label_to_str(l
, str
, ltype
, DEF_NAMES
) != 0)
96 *str
= strdup(gettext("translation failed"));
100 print_rhtp(const char *rhtp_name
)
104 const m_label_t
*l1
, *l2
;
107 (void) strlcpy(tp
.name
, rhtp_name
, sizeof (tp
.name
));
109 if (tnrhtp(TNDB_GET
, &tp
) != 0) {
111 (void) fprintf(stderr
, gettext("tninfo: tnrhtp entry "
112 "%1$s does not exist\n"), tp
.name
);
114 (void) fprintf(stderr
,
115 gettext("tninfo: tnrhtp TNDB_GET(%1$s) failed: "
116 "%2$s\n"), tp
.name
, strerror(errno
));
120 (void) printf("=====================================\n");
121 (void) printf(gettext("Remote Host Template Table Entries:\n"));
123 (void) printf("__________________________\n");
124 (void) printf(gettext("template: %s\n"), tp
.name
);
126 switch (tp
.host_type
) {
128 (void) printf(gettext("host_type: UNLABELED\n"));
129 (void) printf(gettext("doi: %d\n"), tp
.tp_doi
);
131 if (tp
.tp_mask_unl
& TSOL_MSK_DEF_LABEL
) {
132 l_to_str(&tp
.tp_def_label
, &str
, M_LABEL
);
133 l_to_str(&tp
.tp_def_label
, &str2
, M_INTERNAL
);
134 (void) printf(gettext("def_label: %s\nhex: %s\n"),
140 if (tp
.tp_mask_unl
& TSOL_MSK_SL_RANGE_TSOL
) {
141 (void) printf(gettext("For routing only:\n"));
142 l_to_str(&tp
.tp_gw_sl_range
.lower_bound
,
144 l_to_str(&tp
.tp_gw_sl_range
.lower_bound
,
146 (void) printf(gettext("min_sl: %s\nhex: %s\n"),
151 l_to_str(&tp
.tp_gw_sl_range
.upper_bound
,
153 l_to_str(&tp
.tp_gw_sl_range
.upper_bound
,
155 (void) printf(gettext("max_sl: %s\nhex: %s\n"),
160 l1
= (const m_label_t
*)&tp
.tp_gw_sl_set
[0];
161 l2
= (const m_label_t
*)&tp
.tp_gw_sl_set
[NSLS_MAX
];
162 for (i
= 0; l1
< l2
; l1
++, i
++) {
163 if (label_to_str(l1
, &str2
, M_INTERNAL
,
166 l_to_str(l1
, &str
, M_LABEL
);
167 (void) printf(gettext("sl_set[%1$d]: %2$s\n"
168 "hex: %3$s\n"), i
, str
, str2
);
176 (void) printf(gettext("host_type: CIPSO\n"));
177 (void) printf(gettext("doi: %d\n"), tp
.tp_doi
);
178 if (tp
.tp_mask_cipso
& TSOL_MSK_SL_RANGE_TSOL
) {
179 l_to_str(&tp
.tp_sl_range_cipso
.lower_bound
,
181 l_to_str(&tp
.tp_sl_range_cipso
.lower_bound
,
184 (void) printf(gettext("min_sl: %s\nhex: %s\n"),
189 l_to_str(&tp
.tp_sl_range_cipso
.upper_bound
,
191 l_to_str(&tp
.tp_sl_range_cipso
.upper_bound
,
194 (void) printf(gettext("max_sl: %s\nhex: %s\n"),
199 l1
= (const m_label_t
*)&tp
.tp_sl_set_cipso
[0];
200 l2
= (const m_label_t
*)&tp
.tp_sl_set_cipso
[NSLS_MAX
];
201 for (i
= 0; l1
< l2
; l1
++, i
++) {
202 if (label_to_str(l1
, &str2
, M_INTERNAL
,
205 l_to_str(l1
, &str
, M_LABEL
);
207 (void) printf(gettext("sl_set[%1$d]: %2$s\n"
208 "hex: %3$s\n"), i
, str
, str2
);
216 (void) printf(gettext("unsupported host type: %ld\n"),
223 print_rh(const char *rh_name
)
228 char abuf
[INET6_ADDRSTRLEN
];
231 if ((hp
= getipnodebyname(rh_name
, AF_INET6
,
232 AI_ALL
| AI_ADDRCONFIG
| AI_V4MAPPED
, &herr
)) == NULL
) {
233 (void) fprintf(stderr
, gettext("tninfo: unknown host or "
234 "invalid literal address: %s\n"), rh_name
);
235 if (herr
== TRY_AGAIN
)
236 (void) fprintf(stderr
,
237 gettext("\t(try again later)\n"));
241 (void) memset(&rhent
, 0, sizeof (rhent
));
242 (void) memcpy(&in6
, hp
->h_addr
, hp
->h_length
);
244 if (IN6_IS_ADDR_V4MAPPED(&in6
)) {
245 rhent
.rh_address
.ta_family
= AF_INET
;
246 IN6_V4MAPPED_TO_INADDR(&in6
, &rhent
.rh_address
.ta_addr_v4
);
247 (void) inet_ntop(AF_INET
, &rhent
.rh_address
.ta_addr_v4
, abuf
,
250 rhent
.rh_address
.ta_family
= AF_INET6
;
251 rhent
.rh_address
.ta_addr_v6
= in6
;
252 (void) inet_ntop(AF_INET6
, &in6
, abuf
, sizeof (abuf
));
255 (void) printf(gettext("IP address= %s\n"), abuf
);
257 if (tnrh(TNDB_GET
, &rhent
) != 0) {
259 (void) fprintf(stderr
, gettext("tninfo: tnrhdb entry "
260 "%1$s does not exist\n"), abuf
);
262 (void) fprintf(stderr
, gettext("tninfo: TNDB_GET(%1$s) "
263 "failed: %2$s\n"), abuf
, strerror(errno
));
267 if (rhent
.rh_template
[0] != '\0')
268 (void) printf(gettext("Template = %.*s\n"), TNTNAMSIZ
,
271 (void) printf(gettext("No template exists.\n"));
277 iterate_mlps(tsol_mlpent_t
*tsme
, const char *type
)
281 /* get the first entry */
282 tsme
->tsme_mlp
.mlp_ipp
= 0;
283 tsme
->tsme_mlp
.mlp_port
= 0;
284 tsme
->tsme_mlp
.mlp_port_upper
= 0;
285 if (tnmlp(TNDB_GET
, tsme
) == -1) {
286 if (errno
== ENOENT
) {
287 (void) printf(gettext("%s: no entries\n"), type
);
290 perror("tnmlp TNDB_GET");
294 (void) printf("%s: ", type
);
296 (void) printf("%u", tsme
->tsme_mlp
.mlp_port
);
297 if (tsme
->tsme_mlp
.mlp_port
!= tsme
->tsme_mlp
.mlp_port_upper
)
298 (void) printf("-%u", tsme
->tsme_mlp
.mlp_port_upper
);
299 if ((pe
= getprotobynumber(tsme
->tsme_mlp
.mlp_ipp
)) == NULL
)
300 (void) printf("/%u", tsme
->tsme_mlp
.mlp_ipp
);
302 (void) printf("/%s", pe
->p_name
);
303 if (tsme
->tsme_mlp
.mlp_ipp
== 255) {
304 tsme
->tsme_mlp
.mlp_port
++;
305 tsme
->tsme_mlp
.mlp_ipp
= 0;
307 tsme
->tsme_mlp
.mlp_ipp
++;
309 if (tnmlp(TNDB_GET
, tsme
) == -1)
313 (void) putchar('\n');
318 * Print all of the MLPs for the given zone.
321 print_mlp(const char *zonename
)
325 if ((tsme
.tsme_zoneid
= getzoneidbyname(zonename
)) == -1) {
326 (void) fprintf(stderr
, gettext("tninfo: zone '%s' unknown\n"),
331 if (iterate_mlps(&tsme
, gettext("private")) == -1)
333 tsme
.tsme_flags
= TSOL_MEF_SHARED
;
334 if (iterate_mlps(&tsme
, gettext("shared")) == -1)