1209 #include <arpa/inet.h> |
1252 #include <arpa/inet.h> |
1210 +#include <errno.h> |
1253 +#include <errno.h> |
1211 |
1254 |
1212 #include <infiniband/umad.h> |
1255 #include <infiniband/umad.h> |
1213 #include <infiniband/mad.h> |
1256 #include <infiniband/mad.h> |
1214 @@ -57,10 +58,18 @@ |
1257 @@ -57,10 +58,15 @@ |
1215 |
1258 |
1216 memset(sm_id, 0, sizeof(*sm_id)); |
1259 memset(sm_id, 0, sizeof(*sm_id)); |
1217 |
1260 |
1218 - if (!smp_query_via(portinfo, &self, IB_ATTR_PORT_INFO, 0, 0, srcport)) |
1261 - if (!smp_query_via(portinfo, &self, IB_ATTR_PORT_INFO, 0, 0, srcport)) |
1219 + if (!smp_query_via(portinfo, &self, IB_ATTR_PORT_INFO, 0, 0, srcport)) { |
1262 + if (!smp_query_via(portinfo, &self, IB_ATTR_PORT_INFO, 0, 0, srcport)) { |
1220 + if (!errno) |
|
1221 + errno = EIO; |
|
1222 return -1; |
1263 return -1; |
1223 + } |
1264 + } |
1224 |
1265 |
1225 mad_decode_field(portinfo, IB_PORT_SMLID_F, &lid); |
1266 mad_decode_field(portinfo, IB_PORT_SMLID_F, &lid); |
1226 + if (lid == 0) { |
1267 + if (!IB_LID_VALID(lid)) { |
1227 + if (!errno) |
1268 + errno = ENXIO; |
1228 + errno = EIO; |
|
1229 + return -1; |
1269 + return -1; |
1230 + } |
1270 + } |
1231 mad_decode_field(portinfo, IB_PORT_SMSL_F, &sm_id->sl); |
1271 mad_decode_field(portinfo, IB_PORT_SMSL_F, &sm_id->sl); |
1232 |
1272 |
1233 return ib_portid_set(sm_id, lid, 0, 0); |
1273 return ib_portid_set(sm_id, lid, 0, 0); |
1234 @@ -95,7 +104,7 @@ |
1274 @@ -75,11 +81,13 @@ |
|
1275 ib_portid_t * sm_id, int timeout, |
|
1276 const struct ibmad_port *srcport) |
|
1277 { |
|
1278 - ib_portid_t sm_portid; |
|
1279 + ib_portid_t sm_portid = { 0 }; |
|
1280 char buf[IB_SA_DATA_SIZE] = { 0 }; |
|
1281 |
|
1282 - if (!sm_id) { |
|
1283 + if (!sm_id) |
|
1284 sm_id = &sm_portid; |
|
1285 + |
|
1286 + if (!IB_LID_VALID(sm_id->lid)) { |
|
1287 if (ib_resolve_smlid_via(sm_id, timeout, srcport) < 0) |
|
1288 return -1; |
|
1289 } |
|
1290 @@ -95,7 +103,7 @@ |
1235 ib_portid_t * sm_id, int timeout, |
1291 ib_portid_t * sm_id, int timeout, |
1236 const struct ibmad_port *srcport) |
1292 const struct ibmad_port *srcport) |
1237 { |
1293 { |
1238 - ib_portid_t sm_portid; |
1294 - ib_portid_t sm_portid; |
1239 + ib_portid_t sm_portid = { 0 }; |
1295 + ib_portid_t sm_portid = { 0 }; |
1240 uint8_t buf[IB_SA_DATA_SIZE] = { 0 }; |
1296 uint8_t buf[IB_SA_DATA_SIZE] = { 0 }; |
1241 ib_portid_t self = { 0 }; |
1297 ib_portid_t self = { 0 }; |
1242 uint64_t selfguid, prefix; |
1298 uint64_t selfguid, prefix; |
1243 @@ -102,14 +111,19 @@ |
1299 @@ -102,14 +110,17 @@ |
1244 ibmad_gid_t selfgid; |
1300 ibmad_gid_t selfgid; |
1245 uint8_t nodeinfo[64]; |
1301 uint8_t nodeinfo[64]; |
1246 |
1302 |
1247 - if (!sm_id) { |
1303 - if (!sm_id) { |
1248 + if (!sm_id) |
1304 + if (!sm_id) |
1249 sm_id = &sm_portid; |
1305 sm_id = &sm_portid; |
1250 + |
1306 + |
1251 + if (!sm_id->lid) { |
1307 + if (!IB_LID_VALID(sm_id->lid)) { |
1252 if (ib_resolve_smlid_via(sm_id, timeout, srcport) < 0) |
1308 if (ib_resolve_smlid_via(sm_id, timeout, srcport) < 0) |
1253 return -1; |
1309 return -1; |
1254 } |
1310 } |
1255 |
1311 |
1256 - if (!smp_query_via(nodeinfo, &self, IB_ATTR_NODE_INFO, 0, 0, srcport)) |
1312 - if (!smp_query_via(nodeinfo, &self, IB_ATTR_NODE_INFO, 0, 0, srcport)) |
1257 + if (!smp_query_via(nodeinfo, &self, IB_ATTR_NODE_INFO, 0, 0, srcport)) { |
1313 + if (!smp_query_via(nodeinfo, &self, IB_ATTR_NODE_INFO, 0, 0, srcport)) { |
1258 + if (!errno) |
|
1259 + errno = EIO; |
|
1260 return -1; |
1314 return -1; |
1261 + } |
1315 + } |
1262 mad_decode_field(nodeinfo, IB_NODE_PORT_GUID_F, &selfguid); |
1316 mad_decode_field(nodeinfo, IB_NODE_PORT_GUID_F, &selfguid); |
1263 mad_set_field64(selfgid, 0, IB_GID_PREFIX_F, IB_DEFAULT_SUBN_PREFIX); |
1317 mad_set_field64(selfgid, 0, IB_GID_PREFIX_F, IB_DEFAULT_SUBN_PREFIX); |
1264 mad_set_field64(selfgid, 0, IB_GID_GUID_F, selfguid); |
1318 mad_set_field64(selfgid, 0, IB_GID_GUID_F, selfguid); |
|
1319 @@ -145,18 +156,24 @@ |
|
1320 switch (dest_type) { |
|
1321 case IB_DEST_LID: |
|
1322 lid = strtol(addr_str, 0, 0); |
|
1323 - if (!IB_LID_VALID(lid)) |
|
1324 + if (!IB_LID_VALID(lid)) { |
|
1325 + errno = EINVAL; |
|
1326 return -1; |
|
1327 + } |
|
1328 return ib_portid_set(portid, lid, 0, 0); |
|
1329 |
|
1330 case IB_DEST_DRPATH: |
|
1331 - if (str2drpath(&portid->drpath, addr_str, 0, 0) < 0) |
|
1332 + if (str2drpath(&portid->drpath, addr_str, 0, 0) < 0) { |
|
1333 + errno = EINVAL; |
|
1334 return -1; |
|
1335 + } |
|
1336 return 0; |
|
1337 |
|
1338 case IB_DEST_GUID: |
|
1339 - if (!(guid = strtoull(addr_str, 0, 0))) |
|
1340 + if (!(guid = strtoull(addr_str, 0, 0))) { |
|
1341 + errno = EINVAL; |
|
1342 return -1; |
|
1343 + } |
|
1344 |
|
1345 /* keep guid in portid? */ |
|
1346 return ib_resolve_guid_via(portid, &guid, sm_id, 0, srcport); |
|
1347 @@ -164,8 +181,10 @@ |
|
1348 case IB_DEST_DRSLID: |
|
1349 lid = strtol(addr_str, &routepath, 0); |
|
1350 routepath++; |
|
1351 - if (!IB_LID_VALID(lid)) |
|
1352 + if (!IB_LID_VALID(lid)) { |
|
1353 + errno = EINVAL; |
|
1354 return -1; |
|
1355 + } |
|
1356 ib_portid_set(portid, lid, 0, 0); |
|
1357 |
|
1358 /* handle DR parsing and set DrSLID to local lid */ |
|
1359 @@ -172,8 +191,10 @@ |
|
1360 if (ib_resolve_self_via(&selfportid, &selfport, 0, srcport) < 0) |
|
1361 return -1; |
|
1362 if (str2drpath(&portid->drpath, routepath, selfportid.lid, 0) < |
|
1363 - 0) |
|
1364 + 0) { |
|
1365 + errno = EINVAL; |
|
1366 return -1; |
|
1367 + } |
|
1368 return 0; |
|
1369 |
|
1370 case IB_DEST_GID: |
|
1371 @@ -182,6 +203,7 @@ |
|
1372 return ib_resolve_gid_via(portid, gid, sm_id, 0, srcport); |
|
1373 default: |
|
1374 IBWARN("bad dest_type %d", dest_type); |
|
1375 + errno = EINVAL; |
|
1376 } |
|
1377 |
|
1378 return -1; |
1265 diff -r -u /tmp/libibmad-1.3.7/src/dump.c libibmad-1.3.7/src/dump.c |
1379 diff -r -u /tmp/libibmad-1.3.7/src/dump.c libibmad-1.3.7/src/dump.c |
1266 --- /tmp/libibmad-1.3.7/src/dump.c Wed Feb 16 02:12:53 2011 |
1380 --- /tmp/libibmad-1.3.7/src/dump.c Wed Feb 16 02:12:53 2011 |
1267 +++ libibmad-1.3.7/src/dump.c Mon May 27 17:23:19 2013 |
1381 +++ libibmad-1.3.7/src/dump.c Mon May 27 17:23:19 2013 |
1268 @@ -46,12 +46,24 @@ |
1382 @@ -308,6 +308,21 @@ |
1269 |
|
1270 void mad_dump_int(char *buf, int bufsz, void *val, int valsz) |
|
1271 { |
|
1272 + /* |
|
1273 + * the val pointer passed to the dump routines are always 32 bit |
|
1274 + * integers for valsz <= 4 and 64 bit integer for the rest. It is never |
|
1275 + * uint8_t or uint16_t. This is because mad_decode_field always returns |
|
1276 + * the values as 32 bit integer even if they are 8 bit or 16 bit fields. |
|
1277 + */ |
|
1278 switch (valsz) { |
|
1279 case 1: |
|
1280 - snprintf(buf, bufsz, "%d", *(uint32_t *) val & 0xff); |
|
1281 +#if defined(_BIG_ENDIAN) |
|
1282 + val = ((uint8_t *)val) + 3; |
|
1283 +#endif /* _BIG_ENDIAN */ |
|
1284 + snprintf(buf, bufsz, "%d", *(uint8_t *) val & 0xff); |
|
1285 break; |
|
1286 case 2: |
|
1287 - snprintf(buf, bufsz, "%d", *(uint32_t *) val & 0xffff); |
|
1288 +#if defined(_BIG_ENDIAN) |
|
1289 + val = ((uint16_t *)val) + 1; |
|
1290 +#endif /* _BIG_ENDIAN */ |
|
1291 + snprintf(buf, bufsz, "%d", *(uint16_t *) val & 0xffff); |
|
1292 break; |
|
1293 case 3: |
|
1294 case 4: |
|
1295 @@ -71,12 +83,24 @@ |
|
1296 |
|
1297 void mad_dump_uint(char *buf, int bufsz, void *val, int valsz) |
|
1298 { |
|
1299 + /* |
|
1300 + * the val pointer passed to the dump routines are always 32 bit |
|
1301 + * integers for valsz <= 4 and 64 bit integer for the rest. It is never |
|
1302 + * uint8_t or uint16_t. This is because mad_decode_field always returns |
|
1303 + * the values as 32 bit integer even if they are 8 bit or 16 bit fields. |
|
1304 + */ |
|
1305 switch (valsz) { |
|
1306 case 1: |
|
1307 - snprintf(buf, bufsz, "%u", *(uint32_t *) val & 0xff); |
|
1308 +#if defined(_BIG_ENDIAN) |
|
1309 + val = ((uint8_t *)val) + 3; |
|
1310 +#endif /* _BIG_ENDIAN */ |
|
1311 + snprintf(buf, bufsz, "%u", *(uint8_t *) val & 0xff); |
|
1312 break; |
|
1313 case 2: |
|
1314 - snprintf(buf, bufsz, "%u", *(uint32_t *) val & 0xffff); |
|
1315 +#if defined(_BIG_ENDIAN) |
|
1316 + val = ((uint16_t *)val) + 1; |
|
1317 +#endif /* _BIG_ENDIAN */ |
|
1318 + snprintf(buf, bufsz, "%u", *(uint16_t *) val & 0xffff); |
|
1319 break; |
|
1320 case 3: |
|
1321 case 4: |
|
1322 @@ -96,15 +120,28 @@ |
|
1323 |
|
1324 void mad_dump_hex(char *buf, int bufsz, void *val, int valsz) |
|
1325 { |
|
1326 + /* |
|
1327 + * the val pointer passed to the dump routines are always 32 bit |
|
1328 + * integers for valsz <= 4 and 64 bit integer for the rest. It is never |
|
1329 + * uint8_t or uint16_t. This is because mad_decode_field always returns |
|
1330 + * the values as 32 bit integer even if they are 8 bit or 16 bit fields. |
|
1331 + */ |
|
1332 switch (valsz) { |
|
1333 case 1: |
|
1334 - snprintf(buf, bufsz, "0x%02x", *(uint32_t *) val & 0xff); |
|
1335 +#if defined(_BIG_ENDIAN) |
|
1336 + val = ((uint8_t *)val) + 3; |
|
1337 +#endif /* _BIG_ENDIAN */ |
|
1338 + snprintf(buf, bufsz, "0x%02x", *(uint8_t *) val & 0xff); |
|
1339 break; |
|
1340 case 2: |
|
1341 - snprintf(buf, bufsz, "0x%04x", *(uint32_t *) val & 0xffff); |
|
1342 +#if defined(_BIG_ENDIAN) |
|
1343 + val = ((uint16_t *)val) + 1; |
|
1344 +#endif /* _BIG_ENDIAN */ |
|
1345 + snprintf(buf, bufsz, "0x%04x", *(uint16_t *) val & 0xffff); |
|
1346 break; |
|
1347 case 3: |
|
1348 - snprintf(buf, bufsz, "0x%06x", *(uint32_t *) val & 0xffffff); |
|
1349 + //snprintf(buf, bufsz, "0x%06x", *(uint32_t *) val & 0xffffff); |
|
1350 + snprintf(buf, bufsz, "0x%x", *(uint32_t *)val & 0xffffff); |
|
1351 break; |
|
1352 case 4: |
|
1353 snprintf(buf, bufsz, "0x%08x", *(uint32_t *) val); |
|
1354 @@ -132,12 +169,24 @@ |
|
1355 |
|
1356 void mad_dump_rhex(char *buf, int bufsz, void *val, int valsz) |
|
1357 { |
|
1358 + /* |
|
1359 + * the val pointer passed to the dump routines are always 32 bit |
|
1360 + * integers for valsz <= 4 and 64 bit integer for the rest. It is never |
|
1361 + * uint8_t or uint16_t. This is because mad_decode_field always returns |
|
1362 + * the values as 32 bit integer even if they are 8 bit or 16 bit fields. |
|
1363 + */ |
|
1364 switch (valsz) { |
|
1365 case 1: |
|
1366 - snprintf(buf, bufsz, "%02x", *(uint32_t *) val & 0xff); |
|
1367 +#if defined(_BIG_ENDIAN) |
|
1368 + val = ((uint8_t *)val) + 3; |
|
1369 +#endif /* _BIG_ENDIAN */ |
|
1370 + snprintf(buf, bufsz, "%02x", *(uint8_t *) val & 0xff); |
|
1371 break; |
|
1372 case 2: |
|
1373 - snprintf(buf, bufsz, "%04x", *(uint32_t *) val & 0xffff); |
|
1374 +#if defined(_BIG_ENDIAN) |
|
1375 + val = ((uint16_t *)val) + 1; |
|
1376 +#endif /* _BIG_ENDIAN */ |
|
1377 + snprintf(buf, bufsz, "%04x", *(uint16_t *) val & 0xffff); |
|
1378 break; |
|
1379 case 3: |
|
1380 snprintf(buf, bufsz, "%06x", *(uint32_t *) val & 0xffffff); |
|
1381 @@ -308,6 +357,21 @@ |
|
1382 dump_linkspeed(buf, bufsz, speed); |
1383 dump_linkspeed(buf, bufsz, speed); |
1383 } |
1384 } |
1384 |
1385 |
1385 +void mad_dump_linkspeedext(char *buf, int bufsz, void *val, int valsz) |
1386 +void mad_dump_linkspeedext(char *buf, int bufsz, void *val, int valsz) |
1386 +{ |
1387 +{ |