5252#include "opal/mca/if/if.h"
5353#include "opal/mca/if/base/base.h"
5454
55+ #define LOG_PREFIX "mca: if: linux_ipv6: "
56+
5557static int if_linux_ipv6_open (void );
5658
5759/* Discovers Linux IPv6 interfaces */
@@ -77,19 +79,32 @@ opal_if_base_component_t mca_if_linux_ipv6_component = {
7779 },
7880};
7981
80- static int hex2int (char hex )
82+ static bool hex2int (char hex , int * dst )
8183{
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 ();
84+ if ('0' <= hex && hex <= '9' ) {
85+ * dst = hex - '0' ;
86+ } else if ('A' <= hex && hex <= 'F' ) {
87+ * dst = hex - 'A' + 10 ;
88+ } else if ('a' <= hex && hex <= 'f' ) {
89+ * dst = hex - 'a' + 10 ;
90+ } else {
91+ return false;
92+ }
93+ return true;
94+
8695}
8796
88- static void hexdecode (const char * src , char * dst , size_t dstsize )
97+ static bool hexdecode (const char * src , char * dst , size_t dstsize )
8998{
99+ int hi , lo ;
90100 for (size_t i = 0 ; i < dstsize ; i ++ ) {
91- dst [i ] = hex2int (src [i * 2 ]) * 16 + hex2int (src [i * 2 + 1 ]);
101+ if (hex2int (src [i * 2 ], & hi ) && hex2int (src [i * 2 + 1 ], & lo )) {
102+ dst [i ] = 16 * hi + lo ;
103+ } else {
104+ return false;
105+ }
92106 }
107+ return true;
93108}
94109
95110static int if_linux_ipv6_open (void )
@@ -108,24 +123,28 @@ static int if_linux_ipv6_open(void)
108123 & idx , & pfxlen , & scope , & dadstat , ifname ) != EOF ) {
109124 opal_if_t * intf ;
110125
111- hexdecode (addrhex , a6 .s6_addr , sizeof a6 .s6_addr );
126+ if (!hexdecode (addrhex , a6 .s6_addr , sizeof a6 .s6_addr )) {
127+ opal_output (0 , LOG_PREFIX "skipped interface %s: failed to hexdecode %s\n" ,
128+ ifname , addrhex );
129+ continue ;
130+ };
112131 inet_ntop (AF_INET6 , a6 .s6_addr , addrstr , sizeof addrstr );
113132
114133 opal_output_verbose (1 , opal_if_base_framework .framework_output ,
115- "found interface %s inet6 %s scope %x\n" ,
134+ LOG_PREFIX "found interface %s inet6 %s scope %x\n" ,
116135 ifname , addrstr , scope );
117136
118137 /* Only interested in global (0x00) scope */
119138 if (scope != 0x00 ) {
120139 opal_output_verbose (1 , opal_if_base_framework .framework_output ,
121- "skipped interface %s inet6 %s scope %x\n" ,
140+ LOG_PREFIX "skipped interface %s inet6 %s scope %x\n" ,
122141 ifname , addrstr , scope );
123142 continue ;
124143 }
125144
126145 intf = OBJ_NEW (opal_if_t );
127146 if (NULL == intf ) {
128- opal_output (0 , "opal_ifinit: unable to allocate %lu bytes\n" ,
147+ opal_output (0 , LOG_PREFIX " unable to allocate %lu bytes\n" ,
129148 (unsigned long )sizeof (opal_if_t ));
130149 fclose (f );
131150 return OPAL_ERR_OUT_OF_RESOURCE ;
@@ -150,7 +169,7 @@ static int if_linux_ipv6_open(void)
150169 to list */
151170 opal_list_append (& opal_if_list , & (intf -> super ));
152171 opal_output_verbose (1 , opal_if_base_framework .framework_output ,
153- "added interface %s inet6 %s scope %x\n" ,
172+ LOG_PREFIX "added interface %s inet6 %s scope %x\n" ,
154173 ifname , addrstr , scope );
155174 } /* of while */
156175 fclose (f );
0 commit comments