| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <string.h> |
| #include <arpa/inet.h> |
| |
| #include <infiniband/mad.h> |
| |
| #undef DEBUG |
| #define DEBUG if (ibdebug) IBWARN |
| |
| int portid2portnum(ib_portid_t * portid) |
| { |
| if (portid->lid > 0) |
| return -1; |
| |
| if (portid->drpath.cnt == 0) |
| return 0; |
| |
| return portid->drpath.p[(portid->drpath.cnt - 1)]; |
| } |
| |
| char *portid2str(ib_portid_t * portid) |
| { |
| static char buf[1024] = "local"; |
| int n = 0; |
| |
| if (portid->lid > 0) { |
| n += sprintf(buf + n, "Lid %d", portid->lid); |
| if (portid->grh_present) { |
| char gid[sizeof |
| "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"]; |
| if (inet_ntop(AF_INET6, portid->gid, gid, sizeof(gid))) |
| n += sprintf(buf + n, " Gid %s", gid); |
| } |
| if (portid->drpath.cnt) |
| n += sprintf(buf + n, " "); |
| else |
| return buf; |
| } |
| n += sprintf(buf + n, "DR path "); |
| drpath2str(&(portid->drpath), buf + n, sizeof(buf) - n); |
| |
| return buf; |
| } |
| |
| int str2drpath(ib_dr_path_t * path, char *routepath, int drslid, int drdlid) |
| { |
| char *s, *str; |
| char *tmp; |
| |
| path->cnt = -1; |
| |
| if (!routepath || !(tmp = strdup(routepath))) |
| goto Exit; |
| |
| DEBUG("DR str: %s", routepath); |
| |
| str = tmp; |
| |
| while (str && *str) { |
| if ((s = strchr(str, ','))) |
| *s = 0; |
| path->p[++path->cnt] = (uint8_t) atoi(str); |
| if (!s) |
| break; |
| str = s + 1; |
| } |
| free(tmp); |
| |
| Exit: |
| path->drdlid = drdlid ? drdlid : 0xffff; |
| path->drslid = drslid ? drslid : 0xffff; |
| |
| return path->cnt; |
| } |
| |
| char *drpath2str(ib_dr_path_t * path, char *dstr, size_t dstr_size) |
| { |
| int i = 0; |
| int rc = snprintf(dstr, dstr_size, "slid %u; dlid %u; %d", |
| path->drslid, path->drdlid, path->p[0]); |
| if (rc >= (int)dstr_size) |
| return dstr; |
| for (i = 1; i <= path->cnt; i++) { |
| rc += snprintf(dstr + rc, dstr_size - rc, ",%d", path->p[i]); |
| if (rc >= (int)dstr_size) |
| break; |
| } |
| return (dstr); |
| } |