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