Skip to content

Commit 8d20aa0

Browse files
committed
Fix if_linux_ipv6 verbose output of interface addresses
Previously the verbose output of if_linux_ipv6_open looked like this: found interface ab c: ab: a b: abc: : a 🔡 scope 0 This changes the output to: found interface eth0 inet6 ab0c🆎a0b🔤0:a00🔡0 scope 0 Signed-off-by: Orivej Desh <[email protected]>
1 parent 5d51b23 commit 8d20aa0

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

opal/mca/if/linux_ipv6/if_linux_ipv6.c

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,21 @@ opal_if_base_component_t mca_if_linux_ipv6_component = {
7777
},
7878
};
7979

80-
/* configure using getifaddrs(3) */
80+
static int hex2int(char hex)
81+
{
82+
if ('0' <= hex && hex <= '9') return hex - '0';
83+
if ('A' <= hex && hex <= 'F') return hex - 'A' + 10;
84+
if ('a' <= hex && hex <= 'f') return hex - 'a' + 10;
85+
abort();
86+
}
87+
88+
static void hexdecode(const char *src, char *dst, size_t dstsize)
89+
{
90+
for (size_t i = 0; i < dstsize; i++) {
91+
dst[i] = hex2int(src[i * 2]) * 16 + hex2int(src[i * 2 + 1]);
92+
}
93+
}
94+
8195
static int if_linux_ipv6_open(void)
8296
{
8397
#if OPAL_ENABLE_IPV6
@@ -86,33 +100,26 @@ static int if_linux_ipv6_open(void)
86100
char ifname[IF_NAMESIZE];
87101
unsigned int idx, pfxlen, scope, dadstat;
88102
struct in6_addr a6;
89-
int iter;
90103
uint32_t flag;
91-
unsigned int addrbyte[16];
104+
char addrhex[sizeof a6.s6_addr * 2 + 1];
105+
char addrstr[INET6_ADDRSTRLEN];
92106

93-
while (fscanf(f, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x %x %x %x %x %20s\n",
94-
&addrbyte[0], &addrbyte[1], &addrbyte[2], &addrbyte[3],
95-
&addrbyte[4], &addrbyte[5], &addrbyte[6], &addrbyte[7],
96-
&addrbyte[8], &addrbyte[9], &addrbyte[10], &addrbyte[11],
97-
&addrbyte[12], &addrbyte[13], &addrbyte[14], &addrbyte[15],
107+
while (fscanf(f, "%s %x %x %x %x %s\n", addrhex,
98108
&idx, &pfxlen, &scope, &dadstat, ifname) != EOF) {
99109
opal_if_t *intf;
100110

111+
hexdecode(addrhex, a6.s6_addr, sizeof a6.s6_addr);
112+
inet_ntop(AF_INET6, a6.s6_addr, addrstr, sizeof addrstr);
113+
101114
opal_output_verbose(1, opal_if_base_framework.framework_output,
102-
"found interface %2x%2x:%2x%2x:%2x%2x:%2x%2x:%2x%2x:%2x%2x:%2x%2x:%2x%2x scope %x\n",
103-
addrbyte[0], addrbyte[1], addrbyte[2], addrbyte[3],
104-
addrbyte[4], addrbyte[5], addrbyte[6], addrbyte[7],
105-
addrbyte[8], addrbyte[9], addrbyte[10], addrbyte[11],
106-
addrbyte[12], addrbyte[13], addrbyte[14], addrbyte[15], scope);
115+
"found interface %s inet6 %s scope %x\n",
116+
ifname, addrstr, scope);
107117

108118
/* Only interested in global (0x00) scope */
109119
if (scope != 0x00) {
110120
opal_output_verbose(1, opal_if_base_framework.framework_output,
111-
"skipping interface %2x%2x:%2x%2x:%2x%2x:%2x%2x:%2x%2x:%2x%2x:%2x%2x:%2x%2x scope %x\n",
112-
addrbyte[0], addrbyte[1], addrbyte[2], addrbyte[3],
113-
addrbyte[4], addrbyte[5], addrbyte[6], addrbyte[7],
114-
addrbyte[8], addrbyte[9], addrbyte[10], addrbyte[11],
115-
addrbyte[12], addrbyte[13], addrbyte[14], addrbyte[15], scope);
121+
"skipped interface %s inet6 %s scope %x\n",
122+
ifname, addrstr, scope);
116123
continue;
117124
}
118125

@@ -125,10 +132,6 @@ static int if_linux_ipv6_open(void)
125132
}
126133
intf->af_family = AF_INET6;
127134

128-
for (iter = 0; iter < 16; iter++) {
129-
a6.s6_addr[iter] = addrbyte[iter];
130-
}
131-
132135
/* now construct the opal_if_t */
133136
opal_string_copy(intf->if_name, ifname, IF_NAMESIZE);
134137
intf->if_index = opal_list_get_size(&opal_if_list)+1;
@@ -147,17 +150,12 @@ static int if_linux_ipv6_open(void)
147150
to list */
148151
opal_list_append(&opal_if_list, &(intf->super));
149152
opal_output_verbose(1, opal_if_base_framework.framework_output,
150-
"added interface %2x%2x:%2x%2x:%2x%2x:%2x%2x:%2x%2x:%2x%2x:%2x%2x:%2x%2x\n",
151-
addrbyte[0], addrbyte[1], addrbyte[2], addrbyte[3],
152-
addrbyte[4], addrbyte[5], addrbyte[6], addrbyte[7],
153-
addrbyte[8], addrbyte[9], addrbyte[10], addrbyte[11],
154-
addrbyte[12], addrbyte[13], addrbyte[14], addrbyte[15]);
153+
"added interface %s inet6 %s scope %x\n",
154+
ifname, addrstr, scope);
155155
} /* of while */
156156
fclose(f);
157157
}
158158
#endif /* OPAL_ENABLE_IPV6 */
159159

160160
return OPAL_SUCCESS;
161161
}
162-
163-

0 commit comments

Comments
 (0)