2 * Copyright (c) 2004-2009 Voltaire Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #endif /* HAVE_CONFIG_H */
41 #include <arpa/inet.h>
43 #include <infiniband/mad.h>
46 #define DEBUG if (ibdebug) IBWARN
48 int portid2portnum(ib_portid_t * portid)
53 if (portid->drpath.cnt == 0)
56 return portid->drpath.p[(portid->drpath.cnt - 1)];
59 char *portid2str(ib_portid_t * portid)
61 static char buf[1024] = "local";
64 if (portid->lid > 0) {
65 n += sprintf(buf + n, "Lid %d", portid->lid);
66 if (portid->grh_present) {
68 "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
69 if (inet_ntop(AF_INET6, portid->gid, gid, sizeof(gid)))
70 n += sprintf(buf + n, " Gid %s", gid);
72 if (portid->drpath.cnt)
73 n += sprintf(buf + n, " ");
77 n += sprintf(buf + n, "DR path ");
78 drpath2str(&(portid->drpath), buf + n, sizeof(buf) - n);
83 int str2drpath(ib_dr_path_t * path, char *routepath, int drslid, int drdlid)
90 if (!routepath || !(tmp = strdup(routepath)))
93 DEBUG("DR str: %s", routepath);
98 if ((s = strchr(str, ',')))
100 path->p[++path->cnt] = (uint8_t) atoi(str);
108 path->drdlid = drdlid ? drdlid : 0xffff;
109 path->drslid = drslid ? drslid : 0xffff;
114 char *drpath2str(ib_dr_path_t * path, char *dstr, size_t dstr_size)
117 int rc = snprintf(dstr, dstr_size, "slid %u; dlid %u; %d",
118 path->drslid, path->drdlid, path->p[0]);
119 if (rc >= (int)dstr_size)
121 for (i = 1; i <= path->cnt; i++) {
122 rc += snprintf(dstr + rc, dstr_size - rc, ",%d", path->p[i]);
123 if (rc >= (int)dstr_size)