2 * Copyright (c) 2004-2008 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 */
45 #define DEBUG if (ibdebug) IBWARN
48 portid2portnum(ib_portid_t *portid)
53 if (portid->drpath.cnt == 0)
56 return portid->drpath.p[(portid->drpath.cnt-1)];
60 portid2str(ib_portid_t *portid)
62 static char buf[1024] = "local";
65 if (portid->lid > 0) {
66 n += sprintf(buf + n, "Lid %d", portid->lid);
67 if (portid->grh_present) {
68 char gid[sizeof "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);
84 str2drpath(ib_dr_path_t *path, char *routepath, int drslid, int drdlid)
86 char *s, *str = routepath;
90 DEBUG("DR str: %s", routepath);
92 if ((s = strchr(str, ',')))
94 path->p[++path->cnt] = (uint8_t)atoi(str);
100 path->drdlid = drdlid ? drdlid : 0xffff;
101 path->drslid = drslid ? drslid : 0xffff;
107 drpath2str(ib_dr_path_t *path, char *dstr, size_t dstr_size)
110 int rc = snprintf(dstr, dstr_size, "slid %d; dlid %d; %d",
111 path->drslid, path->drdlid, path->p[0]);
112 if (rc >= (int) dstr_size)
114 for (i = 1; i <= path->cnt; i++) {
115 rc += snprintf(dstr+rc, dstr_size-rc, ",%d", path->p[i]);
116 if (rc >= (int) dstr_size)