Skip to content

Commit dac2fe1

Browse files
committed
usnic: ensure to use ntohl() for network-order values
1 parent 5124039 commit dac2fe1

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

opal/mca/btl/usnic/btl_usnic_endpoint.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* All rights reserved.
1212
* Copyright (c) 2006 Sandia National Laboratories. All rights
1313
* reserved.
14-
* Copyright (c) 2013-2015 Cisco Systems, Inc. All rights reserved.
14+
* Copyright (c) 2013-2016 Cisco Systems, Inc. All rights reserved.
1515
* $COPYRIGHT$
1616
*
1717
* Additional copyrights may follow
@@ -69,6 +69,7 @@ typedef struct opal_btl_usnic_modex_t {
6969
uint32_t ipv4_addr;
7070
/* Stored in host order */
7171
uint32_t ports[USNIC_NUM_CHANNELS];
72+
/* Stored in network order */
7273
uint32_t netmask;
7374
/* Stored in host order */
7475
uint32_t connectivity_udp_port;

opal/mca/btl/usnic/btl_usnic_util.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013-2015 Cisco Systems, Inc. All rights reserved.
2+
* Copyright (c) 2013-2016 Cisco Systems, Inc. All rights reserved.
33
* $COPYRIGHT$
44
*
55
* Additional copyrights may follow
@@ -115,24 +115,27 @@ opal_btl_usnic_dump_hex(void *vaddr, int len)
115115
* using inet_ntop()).
116116
*/
117117
void opal_btl_usnic_snprintf_ipv4_addr(char *out, size_t maxlen,
118-
uint32_t addr, uint32_t netmask)
118+
uint32_t addr_be, uint32_t netmask_be)
119119
{
120120
int prefixlen;
121+
uint32_t netmask = ntohl(netmask_be);
122+
uint32_t addr = ntohl(addr_be);
121123
uint8_t *p = (uint8_t*) &addr;
124+
122125
if (netmask != 0) {
123126
prefixlen = 33 - ffs(netmask);
124127
snprintf(out, maxlen, "%u.%u.%u.%u/%u",
125-
p[0],
126-
p[1],
127-
p[2],
128128
p[3],
129+
p[2],
130+
p[1],
131+
p[0],
129132
prefixlen);
130133
} else {
131134
snprintf(out, maxlen, "%u.%u.%u.%u",
132-
p[0],
133-
p[1],
135+
p[3],
134136
p[2],
135-
p[3]);
137+
p[1],
138+
p[0]);
136139
}
137140
}
138141

opal/mca/btl/usnic/btl_usnic_util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013-2014 Cisco Systems, Inc. All rights reserved.
2+
* Copyright (c) 2013-2016 Cisco Systems, Inc. All rights reserved.
33
* $COPYRIGHT$
44
*
55
* Additional copyrights may follow
@@ -113,7 +113,7 @@ void opal_btl_usnic_util_abort(const char *msg, const char *file, int line);
113113
* expected to be in network byte order.
114114
*/
115115
void opal_btl_usnic_snprintf_ipv4_addr(char *out, size_t maxlen,
116-
uint32_t addr, uint32_t netmask);
116+
uint32_t addr_be, uint32_t netmask_be);
117117

118118
void opal_btl_usnic_snprintf_bool_array(char *s, size_t slen, bool a[], size_t alen);
119119

0 commit comments

Comments
 (0)