int resolve_guid(char *ca_name, uint8_t ca_port, ib_portid_t *portid, uint64_t *guid, ib_portid_t *sm_id, const struct ibmad_port *srcport) { ib_portid_t sm_portid; uint8_t buf[IB_SA_DATA_SIZE] = { 0 }; uint64_t prefix; ibmad_gid_t selfgid; if (!sm_id) { sm_id = &sm_portid; if (resolve_sm_portid(ca_name, ca_port, sm_id) < 0) return -1; } if (resolve_self(ca_name, ca_port, NULL, NULL, &selfgid) < 0) return -1; memcpy(&prefix, portid->gid, sizeof(prefix)); if (!prefix) mad_set_field64(portid->gid, 0, IB_GID_PREFIX_F, IB_DEFAULT_SUBN_PREFIX); if (guid) mad_set_field64(portid->gid, 0, IB_GID_GUID_F, *guid); if ((portid->lid = ib_path_query_via(srcport, selfgid, portid->gid, sm_id, buf)) < 0) return -1; mad_decode_field(buf, IB_SA_PR_SL_F, &portid->sl); return 0; }
static int send_trap(const char *name, void (*build) (ib_mad_notice_attr_t *, ib_portid_t *)) { ib_portid_t sm_port; ib_portid_t selfportid; int selfport; ib_rpc_t trap_rpc; ib_mad_notice_attr_t notice; if (resolve_self(ibd_ca, ibd_ca_port, &selfportid, &selfport, NULL)) IBEXIT("can't resolve self"); if (resolve_sm_portid(ibd_ca, ibd_ca_port, &sm_port)) IBEXIT("can't resolve SM destination port"); memset(&trap_rpc, 0, sizeof(trap_rpc)); trap_rpc.mgtclass = IB_SMI_CLASS; trap_rpc.method = IB_MAD_METHOD_TRAP; trap_rpc.trid = mad_trid(); trap_rpc.attr.id = NOTICE; trap_rpc.datasz = IB_SMP_DATA_SIZE; trap_rpc.dataoffs = IB_SMP_DATA_OFFS; memset(¬ice, 0, sizeof(notice)); build(¬ice, &selfportid); return mad_send_via(&trap_rpc, &sm_port, NULL, ¬ice, srcport); }
int resolve_gid(char *ca_name, uint8_t ca_port, ib_portid_t * portid, ibmad_gid_t gid, ib_portid_t * sm_id, const struct ibmad_port *srcport) { ib_portid_t sm_portid; char buf[IB_SA_DATA_SIZE] = { 0 }; if (!sm_id) { sm_id = &sm_portid; if (resolve_sm_portid(ca_name, ca_port, sm_id) < 0) return -1; } if ((portid->lid = ib_path_query_via(srcport, gid, gid, sm_id, buf)) < 0) return -1; return 0; }
int main(int argc, char **argv) { char *guid_file = "port_guids.list"; int mgmt_classes[2] = { IB_SMI_CLASS, IB_SMI_DIRECT_CLASS }; ib_portid_t dport_id; int port, agent; uint8_t *umad; int len; if (argc > 1) guid_file = argv[1]; srcport = mad_rpc_open_port(NULL, 0, mgmt_classes, 2); if (!srcport) err("Failed to open port"); resolve_sm_portid(NULL, 0, &dport_id); dport_id.qp = 1; if (!dport_id.qkey) dport_id.qkey = IB_DEFAULT_QP1_QKEY; len = umad_size() + 256; umad = calloc(1, len); if (!umad) { err("cannot alloc mem for umad: %s\n", strerror(errno)); return -1; } port = mad_rpc_portid(srcport); agent = umad_register(port, IB_SA_CLASS, 2, 0, NULL); rereg_and_test_port(guid_file, port, agent, &dport_id, TMO); free(umad); umad_unregister(port, agent); umad_close_port(port); umad_done(); return 0; }