| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
/** |
| 3 |
* This file is part of libnvme. |
| 4 |
* Copyright (c) 2023 Red Hat Inc. |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <stdlib.h> |
| 8 |
#include <stdio.h> |
| 9 |
#include <string.h> |
| 10 |
#include <unistd.h> |
| 11 |
#include <inttypes.h> |
| 12 |
#include "libnvme.h" |
| 13 |
|
| 14 |
static void print_hex(unsigned char *buf, int len) |
| 15 |
{ |
| 16 |
int i; |
| 17 |
|
| 18 |
for (i = 0; i < len; i++, buf++) |
| 19 |
printf("%x", *buf); |
| 20 |
} |
| 21 |
|
| 22 |
static void print_nbft(struct nbft_info *table) |
| 23 |
{ |
| 24 |
unsigned int i, j; |
| 25 |
struct nbft_info_hfi **hfi; |
| 26 |
struct nbft_info_security **sec; |
| 27 |
struct nbft_info_discovery **disc; |
| 28 |
struct nbft_info_subsystem_ns **ssns; |
| 29 |
|
| 30 |
printf("raw_nbft_size=%zd\n", table->raw_nbft_size); |
| 31 |
|
| 32 |
printf("host.id="); |
| 33 |
print_hex(table->host.id, NVME_UUID_LEN); |
| 34 |
printf("\n"); |
| 35 |
printf("host.nqn=%s\n", table->host.nqn); |
| 36 |
printf("host.host_id_configured=%d\n", table->host.host_id_configured); |
| 37 |
printf("host.host_nqn_configured=%d\n", table->host.host_nqn_configured); |
| 38 |
printf("host.primary=%d\n", table->host.primary); |
| 39 |
|
| 40 |
for (hfi = table->hfi_list, i = 0; hfi && *hfi; hfi++, i++) { |
| 41 |
printf("hfi_list[%u]->index=%d\n", i, (*hfi)->index); |
| 42 |
printf("hfi_list[%u]->transport=%.*s\n", i, (int)sizeof((*hfi)->transport), (*hfi)->transport); |
| 43 |
printf("hfi_list[%u]->tcp_info.pci_sbdf=%"PRIu32"\n", i, (*hfi)->tcp_info.pci_sbdf); |
| 44 |
printf("hfi_list[%u]->tcp_info.mac_addr=", i); |
| 45 |
print_hex((*hfi)->tcp_info.mac_addr, sizeof((*hfi)->tcp_info.mac_addr)); |
| 46 |
printf("\n"); |
| 47 |
printf("hfi_list[%u]->tcp_info.vlan=%"PRIu16"\n", i, (*hfi)->tcp_info.vlan); |
| 48 |
printf("hfi_list[%u]->tcp_info.ip_origin=%u\n", i, (*hfi)->tcp_info.ip_origin); |
| 49 |
printf("hfi_list[%u]->tcp_info.ipaddr=%s\n", i, (*hfi)->tcp_info.ipaddr); |
| 50 |
printf("hfi_list[%u]->tcp_info.subnet_mask_prefix=%u\n", i, (*hfi)->tcp_info.subnet_mask_prefix); |
| 51 |
printf("hfi_list[%u]->tcp_info.gateway_ipaddr=%s\n", i, (*hfi)->tcp_info.gateway_ipaddr); |
| 52 |
printf("hfi_list[%u]->tcp_info.route_metric=%"PRIu16"\n", i, (*hfi)->tcp_info.route_metric); |
| 53 |
printf("hfi_list[%u]->tcp_info.primary_dns_ipaddr=%s\n", i, (*hfi)->tcp_info.primary_dns_ipaddr); |
| 54 |
printf("hfi_list[%u]->tcp_info.secondary_dns_ipaddr=%s\n", i, (*hfi)->tcp_info.secondary_dns_ipaddr); |
| 55 |
printf("hfi_list[%u]->tcp_info.dhcp_server_ipaddr=%s\n", i, (*hfi)->tcp_info.dhcp_server_ipaddr); |
| 56 |
printf("hfi_list[%u]->tcp_info.host_name=%s\n", i, (*hfi)->tcp_info.host_name); |
| 57 |
printf("hfi_list[%u]->tcp_info.this_hfi_is_default_route=%d\n", i, (*hfi)->tcp_info.this_hfi_is_default_route); |
| 58 |
printf("hfi_list[%u]->tcp_info.dhcp_override=%d\n", i, (*hfi)->tcp_info.dhcp_override); |
| 59 |
} |
| 60 |
|
| 61 |
for (sec = table->security_list, i = 0; sec && *sec; sec++, i++) { |
| 62 |
printf("security_list[%u]->index=%d\n", i, (*sec)->index); |
| 63 |
} |
| 64 |
|
| 65 |
for (disc = table->discovery_list, i = 0; disc && *disc; disc++, i++) { |
| 66 |
printf("discovery_list[%u]->index=%d\n", i, (*disc)->index); |
| 67 |
if ((*disc)->security) |
| 68 |
printf("discovery_list[%u]->security->index=%d\n", i, (*disc)->security->index); |
| 69 |
if ((*disc)->hfi) |
| 70 |
printf("discovery_list[%u]->hfi->index=%d\n", i, (*disc)->hfi->index); |
| 71 |
printf("discovery_list[%u]->uri=%s\n", i, (*disc)->uri); |
| 72 |
printf("discovery_list[%u]->nqn=%s\n", i, (*disc)->nqn); |
| 73 |
} |
| 74 |
|
| 75 |
for (ssns = table->subsystem_ns_list, i = 0; ssns && *ssns; ssns++, i++) { |
| 76 |
printf("subsystem_ns_list[%u]->index=%d\n", i, (*ssns)->index); |
| 77 |
if ((*ssns)->discovery) |
| 78 |
printf("subsystem_ns_list[%u]->discovery->index=%d\n", i, (*ssns)->discovery->index); |
| 79 |
if ((*ssns)->security) |
| 80 |
printf("subsystem_ns_list[%u]->security->index=%d\n", i, (*ssns)->security->index); |
| 81 |
printf("subsystem_ns_list[%u]->num_hfis=%d\n", i, (*ssns)->num_hfis); |
| 82 |
for (hfi = (*ssns)->hfis, j = 0; hfi && *hfi; hfi++, j++) |
| 83 |
printf("subsystem_ns_list[%u]->hfis[%u]->index=%d\n", i, j, (*hfi)->index); |
| 84 |
printf("subsystem_ns_list[%u]->transport=%s\n", i, (*ssns)->transport); |
| 85 |
printf("subsystem_ns_list[%u]->traddr=%s\n", i, (*ssns)->traddr); |
| 86 |
printf("subsystem_ns_list[%u]->trsvcid=%s\n", i, (*ssns)->trsvcid); |
| 87 |
printf("subsystem_ns_list[%u]->subsys_port_id=%"PRIu16"\n", i, (*ssns)->subsys_port_id); |
| 88 |
printf("subsystem_ns_list[%u]->nsid=%"PRIu32"\n", i, (*ssns)->nsid); |
| 89 |
printf("subsystem_ns_list[%u]->nid_type=%d\n", i, (*ssns)->nid_type); |
| 90 |
printf("subsystem_ns_list[%u]->nid=", i); |
| 91 |
print_hex((*ssns)->nid, 16); |
| 92 |
printf("\n"); |
| 93 |
printf("subsystem_ns_list[%u]->subsys_nqn=%s\n", i, (*ssns)->subsys_nqn); |
| 94 |
printf("subsystem_ns_list[%u]->pdu_header_digest_required=%d\n", i, (*ssns)->pdu_header_digest_required); |
| 95 |
printf("subsystem_ns_list[%u]->data_digest_required=%d\n", i, (*ssns)->data_digest_required); |
| 96 |
printf("subsystem_ns_list[%u]->controller_id=%d\n", i, (*ssns)->controller_id); |
| 97 |
printf("subsystem_ns_list[%u]->asqsz=%d\n", i, (*ssns)->asqsz); |
| 98 |
printf("subsystem_ns_list[%u]->dhcp_root_path_string=%s\n", i, (*ssns)->dhcp_root_path_string); |
| 99 |
printf("subsystem_ns_list[%u]->discovered=%d\n", i, (*ssns)->discovered); |
| 100 |
printf("subsystem_ns_list[%u]->unavailable=%d\n", i, (*ssns)->unavailable); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
int main(int argc, char **argv) |
| 105 |
{ |
| 106 |
struct nbft_info *table = NULL; |
| 107 |
|
| 108 |
if (argc < 2) { |
| 109 |
fprintf(stderr, "Usage: %s TABLE\n", argv[0]); |
| 110 |
return 1; |
| 111 |
} |
| 112 |
|
| 113 |
if (nvme_nbft_read(&table, argv[1]) != 0) { |
| 114 |
fprintf(stderr, "Error parsing the NBFT table %s: %m\n", |
| 115 |
argv[1]); |
| 116 |
return 2; |
| 117 |
} |
| 118 |
|
| 119 |
print_nbft(table); |
| 120 |
|
| 121 |
nvme_nbft_free(table); |
| 122 |
return 0; |
| 123 |
} |