015f8fff605f2fbd5fd0072e555576297804d57bhiremath * CDDL HEADER START
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * The contents of this file are subject to the terms of the
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * Common Development and Distribution License (the "License").
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * You may not use this file except in compliance with the License.
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * See the License for the specific language governing permissions
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * and limitations under the License.
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * When distributing Covered Code, include this CDDL HEADER in each
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * If applicable, add the following below this CDDL HEADER, with the
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * fields enclosed by brackets "[]" replaced with your own identifying
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * information: Portions Copyright [yyyy] [name of copyright owner]
015f8fff605f2fbd5fd0072e555576297804d57bhiremath * CDDL HEADER END
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
015f8fff605f2fbd5fd0072e555576297804d57bhiremathextern char cmlog[];
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmarkextern int ibcm_resolver_pr_lookup(ibcm_arp_streams_t *ib_s,
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath ibt_ip_addr_t *dst_addr, ibt_ip_addr_t *src_addr, zoneid_t myzoneid);
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmarkextern void ibcm_arp_delete_prwqn(ibcm_arp_prwqn_t *wqnp);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath_NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibt_ip_addr_s))
015f8fff605f2fbd5fd0072e555576297804d57bhiremath_NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibcm_arp_ip_t))
015f8fff605f2fbd5fd0072e555576297804d57bhiremath_NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibcm_arp_ibd_insts_t))
015f8fff605f2fbd5fd0072e555576297804d57bhiremath_NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibcm_arp_prwqn_t))
015f8fff605f2fbd5fd0072e555576297804d57bhiremath_NOTE(SCHEME_PROTECTS_DATA("Unshared data", sockaddr_in))
015f8fff605f2fbd5fd0072e555576297804d57bhiremath_NOTE(SCHEME_PROTECTS_DATA("Unshared data", sockaddr_in6))
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath * ibcm_ip_print
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath * label Arbitrary qualifying string
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath * ipa Pointer to IP Address to print
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremathibcm_ip_print(char *label, ibt_ip_addr_t *ipaddr)
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath inet_ntop(AF_INET, &ipaddr->un.ip4addr, buf, sizeof (buf)));
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath } else if (ipaddr->family == AF_INET6) {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L2(cmlog, "%s: %s", label, inet_ntop(AF_INET6,
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath &ipaddr->un.ip6addr, buf, sizeof (buf)));
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L2(cmlog, "%s: IP ADDR NOT SPECIFIED ", label);
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremathibcm_arp_get_ibaddr(zoneid_t myzoneid, ibt_ip_addr_t srcaddr,
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath ibt_ip_addr_t destaddr, ib_gid_t *sgid, ib_gid_t *dgid,
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibaddr(%d, %p, %p, %p, %p, %p)",
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath myzoneid, srcaddr, destaddr, sgid, dgid, saddrp);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath ib_s = (ibcm_arp_streams_t *)kmem_zalloc(sizeof (ibcm_arp_streams_t),
015f8fff605f2fbd5fd0072e555576297804d57bhiremath mutex_init(&ib_s->lock, NULL, MUTEX_DEFAULT, NULL);
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath ret = ibcm_resolver_pr_lookup(ib_s, &destaddr, &srcaddr, myzoneid);
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark IBTF_DPRINTF_L3(cmlog, "ibcm_arp_get_ibaddr: ibcm_resolver_pr_lookup "
015f8fff605f2fbd5fd0072e555576297804d57bhiremath if (ret == 0) {
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath * If the user supplied a address, then verify we got
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath * for the same address.
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath len = (wqnp->usrc_addr.family == AF_INET) ?
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath IBTF_DPRINTF_L3(cmlog, "ibcm_arp_get_ibaddr: "
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath "srcaddr mismatch");
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath /* Clean-up old data, and reset the done flag */
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath ret = ibcm_resolver_pr_lookup(ib_s, &srcaddr,
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath "ibcm_arp_get_ibaddr: "
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath "SGID: %llX:%llX DGID: %llX:%llX",
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath } else if (ret == 0) {
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath bcopy(&wqnp->src_addr, saddrp, sizeof (ibt_ip_addr_t));
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibaddr: SGID: %llX:%llX"
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath " DGID: %llX:%llX", sgid->gid_prefix, sgid->gid_guid,
23a9f846c20554daf41a34c0f67d0184f9bb792fShantkumar Hiremath } else if (ret == 0) {
23a9f846c20554daf41a34c0f67d0184f9bb792fShantkumar Hiremath * We come here only when lookup has returned empty (failed)
bd670b35a010421b6e1a5536c34453a827007c81Erik Nordmark * via callback routine.
23a9f846c20554daf41a34c0f67d0184f9bb792fShantkumar Hiremath * i.e. ib_s->status is non-zero, while ret is zero.
23a9f846c20554daf41a34c0f67d0184f9bb792fShantkumar Hiremath kmem_free(wqnp, sizeof (ibcm_arp_prwqn_t));
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummalaibcm_arp_free_ibds(ibcm_arp_ibd_insts_t *ibds)
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala kmem_free(ibds->ibcm_arp_ip, ibds->ibcm_arp_ibd_alloc *
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummalaibcm_arp_get_ibd_insts(ibcm_arp_ibd_insts_t *ibds)
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala if ((ibt_get_all_part_attr(&attr_list, &nparts) != IBT_SUCCESS) ||
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor IBTF_DPRINTF_L2(cmlog, "ibcm_arp_get_ibd_insts: Failed to "
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibd_insts: Found %d IB Part List",
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala ibds->ibcm_arp_ip = (ibcm_arp_ip_t *)kmem_zalloc(
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala nparts * sizeof (ibcm_arp_ip_t), KM_SLEEP);
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala if (ibt_get_port_state_byguid(attr->pa_hca_guid,
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala attr->pa_port, &port_gid, NULL) == IBT_SUCCESS) {
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala ipp = &ibds->ibcm_arp_ip[ibds->ibcm_arp_ibd_cnt];
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor IBTF_DPRINTF_L4(cmlog, "PartAttr: p-linkid %lX, "
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor "port_gid %llX \n attr-port_guid %llX",
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala (void) ibt_free_part_attr(attr_list, ibds->ibcm_arp_ibd_alloc);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Issue an ioctl down to IP. There are several similar versions of this
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * function (e.g., rpcib_do_ip_ioctl()); clearly a utility routine is needed.
af4c679f647cf088543c762e33d41a3ac52cfa14Sean McEnroe if (lookupname("/dev/udp", UIO_SYSSPACE, FOLLOW, NULLVPP, &kkvp) != 0)
af4c679f647cf088543c762e33d41a3ac52cfa14Sean McEnroe if (t_kopen(NULL, kkvp->v_rdev, FREAD|FWRITE, &tiptr, CRED()) != 0) {
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem err = kstr_ioctl(tiptr->fp->f_vnode, I_STR, (intptr_t)&iocb);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Issue an SIOCGLIFCONF down to IP and return the result in `lifcp'.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * lifcp->lifc_buf is dynamically allocated to be *bufsizep bytes.
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremathibcm_do_lifconf(struct lifconf *lifcp, uint_t *bufsizep, sa_family_t family_loc)
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor lifn.lifn_flags = LIFC_NOXMIT | LIFC_TEMPORARY | LIFC_ALLZONES;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem err = ibcm_do_ip_ioctl(SIOCGLIFNUM, sizeof (struct lifnum), &lifn);
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor IBTF_DPRINTF_L3(cmlog, "ibcm_do_lifconf: Family %d, lifn_count %d",
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Pad the interface count to account for additional interfaces that
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * may have been configured between the SIOCGLIFNUM and SIOCGLIFCONF.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem lifcp->lifc_len = *bufsizep = lifn.lifn_count * sizeof (struct lifreq);
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor lifcp->lifc_flags = LIFC_NOXMIT | LIFC_TEMPORARY | LIFC_ALLZONES;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem err = ibcm_do_ip_ioctl(SIOCGLIFCONF, sizeof (struct lifconf), lifcp);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem if (err != 0) {
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem return (0);
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummalaibcm_arp_lookup(ibcm_arp_ibd_insts_t *ibds, char *linkname)
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor IBTF_DPRINTF_L4(cmlog, "ibcm_arp_lookup: linkname = %s", linkname);
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala * If at first we don't succeed, try again, just in case it is in
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala * hiding. The first call requires the datalink management daemon
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala * (the authorative source of information about name to id mapping)
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala * to be present and answering upcalls, the second does not.
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala if (dls_mgmt_get_linkid(linkname, &linkid) != 0) {
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala if (dls_devnet_macname2linkid(linkname, &linkid) != 0) {
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor IBTF_DPRINTF_L2(cmlog, "ibcm_arp_lookup: could not "
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala for (i = 0; i < ibds->ibcm_arp_ibd_cnt; i++) {
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala if (ibds->ibcm_arp_ip[i].ip_linkid == linkid)
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor IBTF_DPRINTF_L2(cmlog, "ibcm_arp_lookup: returning NULL for "
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Fill in `ibds' with IP addresses tied to IFT_IB IP interfaces. Returns
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * B_TRUE if at least one address was filled in.
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremathibcm_arp_get_ibd_ipaddr(ibcm_arp_ibd_insts_t *ibds, sa_family_t family_loc)
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath if (ibcm_do_lifconf(&lifc, &bufsize, family_loc) != 0)
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibd_ipaddr: Family %d, nifs %d",
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala for (lifrp = lifc.lifc_req, i = 0; i < nifs; i++, lifrp++) {
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor IBTF_DPRINTF_L4(cmlog, "lifr_name : %s, lifr_family :%X, "
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor (void) strlcpy(ifname, lifrp->lifr_name, LIFNAMSIZ);
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor /* Get ZoneId. */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor err = ibcm_do_ip_ioctl(SIOCGLIFZONE, sizeof (struct lifreq),
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor IBTF_DPRINTF_L2(cmlog, "IFZONE ioctl Failed: err = %d",
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor /* Get IfIndex. */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor err = ibcm_do_ip_ioctl(SIOCGLIFINDEX, sizeof (struct lifreq),
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor IBTF_DPRINTF_L2(cmlog, "IFINDEX ioctl Failed: err = %d",
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor /* Get Interface flags. */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor err = ibcm_do_ip_ioctl(SIOCGLIFFLAGS, sizeof (struct lifreq),
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor IBTF_DPRINTF_L2(cmlog, "IFFLAGS ioctl Failed: err = %d",
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor IBTF_DPRINTF_L3(cmlog, "IFGroupName ioctl Failed: "
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor IBTF_DPRINTF_L4(cmlog, "grname : %s, grifname :"
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor " %s, m4ifname : %s, m6ifname : %s",
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor "gi_nv4 %d, gi_nv6 %d, gi_mactype %d",
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor if ((ipp = ibcm_arp_lookup(ibds, ifname)) == NULL)
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor ipp->ip_zoneid = ifzoneid; /* Copy back the zoneid info */
015f8fff605f2fbd5fd0072e555576297804d57bhiremath sizeof (struct sockaddr_in));
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem sizeof (struct sockaddr_in6));
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem return (naddr > 0);
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremathibcm_arp_get_ibds(ibcm_arp_ibd_insts_t *ibdp, sa_family_t family_loc)
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibds(%p)", ibdp);
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IBTF_DPRINTF_L3(cmlog, "ibcm_arp_get_ibds: Found %d ibd instances",
015f8fff605f2fbd5fd0072e555576297804d57bhiremath /* Get the IP addresses of active ports. */
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath if (!ibcm_arp_get_ibd_ipaddr(ibdp, family_loc)) {
015f8fff605f2fbd5fd0072e555576297804d57bhiremath IBTF_DPRINTF_L2(cmlog, "ibcm_arp_get_ibds: failed to get "
015f8fff605f2fbd5fd0072e555576297804d57bhiremath "ibd instance: IBT_SRC_IP_NOT_FOUND");
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath for (i = 0; i < ibdp->ibcm_arp_ibd_cnt; i++) {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath ibcm_arp_ip_t *aip = &ibdp->ibcm_arp_ip[i];
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibds: Linkid %d Family %d "
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala "PKey 0x%lX \n HCAGUID 0x%llX SGID %llX:%llX",
1cfa752f4e24c34133009b0f6c139127a5c461deRamaswamy Tummala aip->ip_linkid, aip->ip_inet_family, aip->ip_pkey,
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath aip->ip_hca_guid, aip->ip_port_gid.gid_prefix,
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibds: IPV4: %s",
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath inet_ntop(AF_INET, &aip->ip_cm_sin.sin_addr, my_buf,
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath } else if (aip->ip_inet_family == AF_INET6) {
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibds: IPV6: %s",
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath inet_ntop(AF_INET6, &aip->ip_cm_sin6.sin6_addr,
d3a82192edbbe93c6027629b50fd93fed5d0e1abShantkumar Hiremath IBTF_DPRINTF_L2(cmlog, "ibcm_arp_get_ibds: Unknown "