xref: /illumos-gate/usr/src/uts/common/io/ib/mgt/ibcm/ibcm_arp.c (revision 33efde4275d24731ef87927237b0ffb0630b6b2d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #include <sys/types.h>
26 #include <sys/ddi.h>
27 #include <sys/sunddi.h>
28 #include <sys/strsubr.h>
29 #include <sys/socket.h>
30 #include <net/if_arp.h>
31 #include <net/if_types.h>
32 #include <sys/sockio.h>
33 #include <sys/pathname.h>
34 
35 #include <sys/ib/mgt/ibcm/ibcm_arp.h>
36 
37 #include <sys/kstr.h>
38 #include <sys/t_kuser.h>
39 
40 #include <sys/dls.h>
41 
42 extern char cmlog[];
43 
44 extern int ibcm_resolver_pr_lookup(ibcm_arp_streams_t *ib_s,
45     ibt_ip_addr_t *dst_addr, ibt_ip_addr_t *src_addr, zoneid_t myzoneid);
46 extern void ibcm_arp_delete_prwqn(ibcm_arp_prwqn_t *wqnp);
47 
48 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibt_ip_addr_s))
49 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibcm_arp_ip_t))
50 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibcm_arp_ibd_insts_t))
51 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibcm_arp_prwqn_t))
52 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", sockaddr_in))
53 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", sockaddr_in6))
54 
55 int ibcm_printip = 0;
56 
57 /*
58  * Function:
59  *	ibcm_ip_print
60  * Input:
61  *	label		Arbitrary qualifying string
62  *	ipa		Pointer to IP Address to print
63  */
64 void
ibcm_ip_print(char * label,ibt_ip_addr_t * ipaddr)65 ibcm_ip_print(char *label, ibt_ip_addr_t *ipaddr)
66 {
67 	char    buf[INET6_ADDRSTRLEN];
68 
69 	if (ipaddr->family == AF_INET) {
70 		IBTF_DPRINTF_L2(cmlog, "%s: %s", label,
71 		    inet_ntop(AF_INET, &ipaddr->un.ip4addr, buf, sizeof (buf)));
72 	} else if (ipaddr->family == AF_INET6) {
73 		IBTF_DPRINTF_L2(cmlog, "%s: %s", label, inet_ntop(AF_INET6,
74 		    &ipaddr->un.ip6addr, buf, sizeof (buf)));
75 	} else {
76 		IBTF_DPRINTF_L2(cmlog, "%s: IP ADDR NOT SPECIFIED ", label);
77 	}
78 }
79 
80 
81 ibt_status_t
ibcm_arp_get_ibaddr(zoneid_t myzoneid,ibt_ip_addr_t srcaddr,ibt_ip_addr_t destaddr,ib_gid_t * sgid,ib_gid_t * dgid,ibt_ip_addr_t * saddrp)82 ibcm_arp_get_ibaddr(zoneid_t myzoneid, ibt_ip_addr_t srcaddr,
83     ibt_ip_addr_t destaddr, ib_gid_t *sgid, ib_gid_t *dgid,
84     ibt_ip_addr_t *saddrp)
85 {
86 	ibcm_arp_streams_t	*ib_s;
87 	ibcm_arp_prwqn_t	*wqnp;
88 	int			ret = 0;
89 	int			len;
90 
91 	IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibaddr(%d, %p, %p, %p, %p, %p)",
92 	    myzoneid, srcaddr, destaddr, sgid, dgid, saddrp);
93 
94 	ib_s = (ibcm_arp_streams_t *)kmem_zalloc(sizeof (ibcm_arp_streams_t),
95 	    KM_SLEEP);
96 
97 	mutex_init(&ib_s->lock, NULL, MUTEX_DEFAULT, NULL);
98 	cv_init(&ib_s->cv, NULL, CV_DRIVER, NULL);
99 
100 	mutex_enter(&ib_s->lock);
101 	ib_s->done = B_FALSE;
102 	mutex_exit(&ib_s->lock);
103 
104 	ret = ibcm_resolver_pr_lookup(ib_s, &destaddr, &srcaddr, myzoneid);
105 
106 	IBTF_DPRINTF_L3(cmlog, "ibcm_arp_get_ibaddr: ibcm_resolver_pr_lookup "
107 	    "returned: %d", ret);
108 	if (ret == 0) {
109 		mutex_enter(&ib_s->lock);
110 		while (ib_s->done != B_TRUE)
111 			cv_wait(&ib_s->cv, &ib_s->lock);
112 		mutex_exit(&ib_s->lock);
113 	}
114 
115 	mutex_enter(&ib_s->lock);
116 	wqnp = ib_s->wqnp;
117 	if (ib_s->status == 0) {
118 		if (sgid)
119 			*sgid = wqnp->sgid;
120 		if (dgid)
121 			*dgid = wqnp->dgid;
122 		/*
123 		 * If the user supplied a address, then verify we got
124 		 * for the same address.
125 		 */
126 		if (wqnp->usrc_addr.family && sgid) {
127 			len = (wqnp->usrc_addr.family == AF_INET) ?
128 			    IP_ADDR_LEN : sizeof (in6_addr_t);
129 			if (bcmp(&wqnp->usrc_addr.un,
130 			    &wqnp->src_addr.un, len)) {
131 				IBTF_DPRINTF_L3(cmlog, "ibcm_arp_get_ibaddr: "
132 				    "srcaddr mismatch");
133 
134 				/* Clean-up old data, and reset the done flag */
135 				ibcm_arp_delete_prwqn(wqnp);
136 				ib_s->done = B_FALSE;
137 				mutex_exit(&ib_s->lock);
138 
139 				ret = ibcm_resolver_pr_lookup(ib_s, &srcaddr,
140 				    &srcaddr, myzoneid);
141 				if (ret == 0) {
142 					mutex_enter(&ib_s->lock);
143 					while (ib_s->done != B_TRUE)
144 						cv_wait(&ib_s->cv, &ib_s->lock);
145 					mutex_exit(&ib_s->lock);
146 				}
147 				mutex_enter(&ib_s->lock);
148 				wqnp = ib_s->wqnp;
149 				if (ib_s->status == 0) {
150 					if (sgid)
151 						*sgid = wqnp->dgid;
152 
153 					if (saddrp)
154 						bcopy(&wqnp->src_addr, saddrp,
155 						    sizeof (ibt_ip_addr_t));
156 
157 					IBTF_DPRINTF_L4(cmlog,
158 					    "ibcm_arp_get_ibaddr: "
159 					    "SGID: %llX:%llX DGID: %llX:%llX",
160 					    sgid->gid_prefix, sgid->gid_guid,
161 					    dgid->gid_prefix, dgid->gid_guid);
162 
163 					ibcm_arp_delete_prwqn(wqnp);
164 				} else if (ret == 0) {
165 					if (wqnp)
166 						kmem_free(wqnp,
167 						    sizeof (ibcm_arp_prwqn_t));
168 				}
169 				goto arp_ibaddr_done;
170 			}
171 		}
172 
173 		if (saddrp)
174 			bcopy(&wqnp->src_addr, saddrp, sizeof (ibt_ip_addr_t));
175 
176 		IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibaddr: SGID: %llX:%llX"
177 		    " DGID: %llX:%llX", sgid->gid_prefix, sgid->gid_guid,
178 		    dgid->gid_prefix, dgid->gid_guid);
179 
180 		ibcm_arp_delete_prwqn(wqnp);
181 	} else if (ret == 0) {
182 		/*
183 		 * We come here only when lookup has returned empty (failed)
184 		 * via callback routine.
185 		 * i.e. ib_s->status is non-zero, while ret is zero.
186 		 */
187 		if (wqnp)
188 			kmem_free(wqnp, sizeof (ibcm_arp_prwqn_t));
189 	}
190 arp_ibaddr_done:
191 	ret = ib_s->status;
192 	mutex_exit(&ib_s->lock);
193 
194 	mutex_destroy(&ib_s->lock);
195 	cv_destroy(&ib_s->cv);
196 	kmem_free(ib_s, sizeof (ibcm_arp_streams_t));
197 
198 	if (ret)
199 		return (IBT_FAILURE);
200 	else
201 		return (IBT_SUCCESS);
202 }
203 
204 void
ibcm_arp_free_ibds(ibcm_arp_ibd_insts_t * ibds)205 ibcm_arp_free_ibds(ibcm_arp_ibd_insts_t *ibds)
206 {
207 	if (ibds->ibcm_arp_ip) {
208 		kmem_free(ibds->ibcm_arp_ip, ibds->ibcm_arp_ibd_alloc *
209 		    sizeof (ibcm_arp_ip_t));
210 		ibds->ibcm_arp_ibd_alloc = 0;
211 		ibds->ibcm_arp_ibd_cnt = 0;
212 		ibds->ibcm_arp_ip = NULL;
213 	}
214 }
215 
216 static void
ibcm_arp_get_ibd_insts(ibcm_arp_ibd_insts_t * ibds)217 ibcm_arp_get_ibd_insts(ibcm_arp_ibd_insts_t *ibds)
218 {
219 	ibcm_arp_ip_t	*ipp;
220 	ib_gid_t	port_gid;
221 	ibt_part_attr_t	*attr_list, *attr;
222 	int		nparts;
223 
224 	if ((ibt_get_all_part_attr(&attr_list, &nparts) != IBT_SUCCESS) ||
225 	    (nparts == 0)) {
226 		IBTF_DPRINTF_L2(cmlog, "ibcm_arp_get_ibd_insts: Failed to "
227 		    "IB Part List - %d", nparts);
228 		ibds->ibcm_arp_ibd_alloc = 0;
229 		ibds->ibcm_arp_ibd_cnt = 0;
230 		ibds->ibcm_arp_ip = NULL;
231 		return;
232 	}
233 	IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibd_insts: Found %d IB Part List",
234 	    nparts);
235 
236 	ibds->ibcm_arp_ibd_alloc = nparts;
237 	ibds->ibcm_arp_ibd_cnt = 0;
238 	ibds->ibcm_arp_ip = (ibcm_arp_ip_t *)kmem_zalloc(
239 	    nparts * sizeof (ibcm_arp_ip_t), KM_SLEEP);
240 
241 	attr = attr_list;
242 	while (nparts--) {
243 		if (ibt_get_port_state_byguid(attr->pa_hca_guid,
244 		    attr->pa_port, &port_gid, NULL) == IBT_SUCCESS) {
245 
246 			ipp = &ibds->ibcm_arp_ip[ibds->ibcm_arp_ibd_cnt];
247 			ipp->ip_linkid = attr->pa_plinkid;
248 			ipp->ip_pkey = attr->pa_pkey;
249 			ipp->ip_hca_guid = attr->pa_hca_guid;
250 			ipp->ip_port_gid = port_gid;
251 			ibds->ibcm_arp_ibd_cnt++;
252 
253 			IBTF_DPRINTF_L4(cmlog, "PartAttr: p-linkid %lX, "
254 			    "d-linkid %lX, pkey 0x%lX", ipp->ip_linkid,
255 			    attr->pa_dlinkid, ipp->ip_pkey);
256 			IBTF_DPRINTF_L4(cmlog, "hca_guid 0x%llX, "
257 			    "port_gid %llX \n attr-port_guid %llX",
258 			    ipp->ip_hca_guid, ipp->ip_port_gid.gid_guid,
259 			    attr->pa_port_guid);
260 		}
261 		attr++;
262 	}
263 
264 	(void) ibt_free_part_attr(attr_list, ibds->ibcm_arp_ibd_alloc);
265 }
266 
267 /*
268  * Issue an ioctl down to IP.  There are several similar versions of this
269  * function (e.g., rpcib_do_ip_ioctl()); clearly a utility routine is needed.
270  */
271 static int
ibcm_do_ip_ioctl(int cmd,int len,void * arg)272 ibcm_do_ip_ioctl(int cmd, int len, void *arg)
273 {
274 	vnode_t *kkvp;
275 	TIUSER  *tiptr;
276 	struct  strioctl iocb;
277 	int	err = 0;
278 
279 	if (lookupname("/dev/udp", UIO_SYSSPACE, FOLLOW, NULLVPP, &kkvp) != 0)
280 		return (EPROTO);
281 
282 	if (t_kopen(NULL, kkvp->v_rdev, FREAD|FWRITE, &tiptr, CRED()) != 0) {
283 		VN_RELE(kkvp);
284 		return (EPROTO);
285 	}
286 
287 	iocb.ic_cmd = cmd;
288 	iocb.ic_timout = 0;
289 	iocb.ic_len = len;
290 	iocb.ic_dp = (caddr_t)arg;
291 	err = kstr_ioctl(tiptr->fp->f_vnode, I_STR, (intptr_t)&iocb);
292 	(void) t_kclose(tiptr, 0);
293 	VN_RELE(kkvp);
294 	return (err);
295 }
296 
297 /*
298  * Issue an SIOCGLIFCONF down to IP and return the result in `lifcp'.
299  * lifcp->lifc_buf is dynamically allocated to be *bufsizep bytes.
300  */
301 static int
ibcm_do_lifconf(struct lifconf * lifcp,uint_t * bufsizep,sa_family_t family_loc)302 ibcm_do_lifconf(struct lifconf *lifcp, uint_t *bufsizep, sa_family_t family_loc)
303 {
304 	int err;
305 	struct lifnum lifn;
306 
307 	bzero(&lifn, sizeof (struct lifnum));
308 	lifn.lifn_family = family_loc;
309 	lifn.lifn_flags = LIFC_NOXMIT | LIFC_TEMPORARY | LIFC_ALLZONES;
310 
311 	err = ibcm_do_ip_ioctl(SIOCGLIFNUM, sizeof (struct lifnum), &lifn);
312 	if (err != 0)
313 		return (err);
314 
315 	IBTF_DPRINTF_L3(cmlog, "ibcm_do_lifconf: Family %d, lifn_count %d",
316 	    family_loc, lifn.lifn_count);
317 	/*
318 	 * Pad the interface count to account for additional interfaces that
319 	 * may have been configured between the SIOCGLIFNUM and SIOCGLIFCONF.
320 	 */
321 	lifn.lifn_count += 4;
322 
323 	bzero(lifcp, sizeof (struct lifconf));
324 	_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*lifcp))
325 	lifcp->lifc_family = family_loc;
326 	lifcp->lifc_len = *bufsizep = lifn.lifn_count * sizeof (struct lifreq);
327 	lifcp->lifc_buf = kmem_zalloc(*bufsizep, KM_SLEEP);
328 	lifcp->lifc_flags = LIFC_NOXMIT | LIFC_TEMPORARY | LIFC_ALLZONES;
329 
330 	err = ibcm_do_ip_ioctl(SIOCGLIFCONF, sizeof (struct lifconf), lifcp);
331 	if (err != 0) {
332 		kmem_free(lifcp->lifc_buf, *bufsizep);
333 		return (err);
334 	}
335 	return (0);
336 }
337 
338 static ibcm_arp_ip_t *
ibcm_arp_lookup(ibcm_arp_ibd_insts_t * ibds,char * linkname)339 ibcm_arp_lookup(ibcm_arp_ibd_insts_t *ibds, char *linkname)
340 {
341 	datalink_id_t	linkid;
342 	int		i;
343 
344 	IBTF_DPRINTF_L4(cmlog, "ibcm_arp_lookup: linkname =  %s", linkname);
345 
346 	/*
347 	 * If at first we don't succeed, try again, just in case it is in
348 	 * hiding. The first call requires the datalink management daemon
349 	 * (the authorative source of information about name to id mapping)
350 	 * to be present and answering upcalls, the second does not.
351 	 */
352 	if (dls_mgmt_get_linkid(linkname, &linkid) != 0) {
353 		if (dls_devnet_macname2linkid(linkname, &linkid) != 0) {
354 			IBTF_DPRINTF_L2(cmlog, "ibcm_arp_lookup: could not "
355 			    "get linkid from linkname (%s)", linkname);
356 			return (NULL);
357 		}
358 	}
359 
360 	for (i = 0; i < ibds->ibcm_arp_ibd_cnt; i++) {
361 		if (ibds->ibcm_arp_ip[i].ip_linkid == linkid)
362 			return (&ibds->ibcm_arp_ip[i]);
363 	}
364 
365 	IBTF_DPRINTF_L2(cmlog, "ibcm_arp_lookup: returning NULL for "
366 	    "linkname (%s)", linkname);
367 	return (NULL);
368 }
369 
370 /*
371  * Fill in `ibds' with IP addresses tied to IFT_IB IP interfaces.  Returns
372  * B_TRUE if at least one address was filled in.
373  */
374 static boolean_t
ibcm_arp_get_ibd_ipaddr(ibcm_arp_ibd_insts_t * ibds,sa_family_t family_loc)375 ibcm_arp_get_ibd_ipaddr(ibcm_arp_ibd_insts_t *ibds, sa_family_t family_loc)
376 {
377 	int i, nifs, naddr = 0;
378 	uint_t bufsize;
379 	struct lifconf lifc;
380 	struct lifreq *lifrp, lifr_copy;
381 	ibcm_arp_ip_t *ipp;
382 	lifgroupinfo_t	lifgr;
383 	int err;
384 	char    ifname[LIFNAMSIZ + 1];
385 	uint64_t	ifflags = 0;
386 	zoneid_t	ifzoneid;
387 
388 	if (ibcm_do_lifconf(&lifc, &bufsize, family_loc) != 0)
389 		return (B_FALSE);
390 
391 	nifs = lifc.lifc_len / sizeof (struct lifreq);
392 
393 	IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibd_ipaddr: Family %d, nifs %d",
394 	    family_loc, nifs);
395 
396 	for (lifrp = lifc.lifc_req, i = 0; i < nifs; i++, lifrp++) {
397 
398 		if (lifrp->lifr_type != IFT_IB)
399 			continue;
400 
401 		IBTF_DPRINTF_L4(cmlog, "\nInterface# : %d", i);
402 		IBTF_DPRINTF_L4(cmlog, "lifr_name : %s, lifr_family :%X, "
403 		    "lifr_type : 0x%lX", lifrp->lifr_name,
404 		    lifrp->lifr_addr.ss_family, lifrp->lifr_type);
405 
406 		(void) strlcpy(ifname, lifrp->lifr_name, LIFNAMSIZ);
407 
408 		/* Get ZoneId. */
409 		lifr_copy = *lifrp;
410 		ifzoneid = 0;
411 		err = ibcm_do_ip_ioctl(SIOCGLIFZONE, sizeof (struct lifreq),
412 		    &lifr_copy);
413 		if (err != 0) {
414 			IBTF_DPRINTF_L2(cmlog, "IFZONE ioctl Failed: err = %d",
415 			    err);
416 		} else  {
417 			IBTF_DPRINTF_L4(cmlog, "lifr_zoneid     : 0x%X",
418 			    lifr_copy.lifr_zoneid);
419 			ifzoneid = lifr_copy.lifr_zoneid;
420 		}
421 
422 		/* Get IfIndex. */
423 		lifr_copy = *lifrp;
424 		err = ibcm_do_ip_ioctl(SIOCGLIFINDEX, sizeof (struct lifreq),
425 		    &lifr_copy);
426 		if (err != 0) {
427 			IBTF_DPRINTF_L2(cmlog, "IFINDEX ioctl Failed: err = %d",
428 			    err);
429 		} else
430 			IBTF_DPRINTF_L4(cmlog, "lifr_index      : 0x%X",
431 			    lifr_copy.lifr_index);
432 
433 		/* Get Interface flags. */
434 		lifr_copy = *lifrp;
435 		err = ibcm_do_ip_ioctl(SIOCGLIFFLAGS, sizeof (struct lifreq),
436 		    &lifr_copy);
437 		if (err != 0) {
438 			IBTF_DPRINTF_L2(cmlog, "IFFLAGS ioctl Failed: err = %d",
439 			    err);
440 		} else  {
441 			ifflags = lifr_copy.lifr_flags;
442 			IBTF_DPRINTF_L4(cmlog, "lifr_flags      : 0x%llX",
443 			    ifflags);
444 		}
445 
446 		lifr_copy = *lifrp;
447 		err = ibcm_do_ip_ioctl(SIOCGLIFGROUPNAME,
448 		    sizeof (struct lifreq), &lifr_copy);
449 		if (err != 0) {
450 			IBTF_DPRINTF_L3(cmlog, "IFGroupName ioctl Failed: "
451 			    "err = %d", err);
452 		}
453 
454 		if (lifr_copy.lifr_groupname[0] != '\0') {
455 			IBTF_DPRINTF_L4(cmlog, "lifr_groupname  : %s",
456 			    lifr_copy.lifr_groupname);
457 			(void) strlcpy(lifgr.gi_grname,
458 			    lifr_copy.lifr_groupname, LIFGRNAMSIZ);
459 			err = ibcm_do_ip_ioctl(SIOCGLIFGROUPINFO,
460 			    sizeof (struct lifgroupinfo), &lifgr);
461 			if (err != 0) {
462 				IBTF_DPRINTF_L2(cmlog, "IFGroupINFO ioctl "
463 				    "Failed: err = %d", err);
464 			} else {
465 				IBTF_DPRINTF_L4(cmlog, "lifgroupinfo details");
466 				IBTF_DPRINTF_L4(cmlog, "grname : %s, grifname :"
467 				    " %s, m4ifname : %s, m6ifname : %s",
468 				    lifgr.gi_grname, lifgr.gi_grifname,
469 				    lifgr.gi_m4ifname, lifgr.gi_m6ifname);
470 				IBTF_DPRINTF_L4(cmlog, "gi_bcifname  : %s",
471 				    lifgr.gi_bcifname);
472 				IBTF_DPRINTF_L4(cmlog, "gi_v4 %d, gi_v6 %d, "
473 				    "gi_nv4 %d, gi_nv6 %d, gi_mactype %d",
474 				    lifgr.gi_v4, lifgr.gi_v6, lifgr.gi_nv4,
475 				    lifgr.gi_nv6, lifgr.gi_mactype);
476 
477 				(void) strlcpy(ifname, lifgr.gi_bcifname,
478 				    LIFNAMSIZ);
479 			}
480 		}
481 
482 		if ((ipp = ibcm_arp_lookup(ibds, ifname)) == NULL)
483 			continue;
484 
485 		ipp->ip_zoneid = ifzoneid;	/* Copy back the zoneid info */
486 		switch (lifrp->lifr_addr.ss_family) {
487 		case AF_INET:
488 			ipp->ip_inet_family = AF_INET;
489 			bcopy(&lifrp->lifr_addr, &ipp->ip_cm_sin,
490 			    sizeof (struct sockaddr_in));
491 			naddr++;
492 			break;
493 		case AF_INET6:
494 			ipp->ip_inet_family = AF_INET6;
495 			bcopy(&lifrp->lifr_addr, &ipp->ip_cm_sin6,
496 			    sizeof (struct sockaddr_in6));
497 			naddr++;
498 			break;
499 		}
500 	}
501 
502 	kmem_free(lifc.lifc_buf, bufsize);
503 	return (naddr > 0);
504 }
505 
506 ibt_status_t
ibcm_arp_get_ibds(ibcm_arp_ibd_insts_t * ibdp,sa_family_t family_loc)507 ibcm_arp_get_ibds(ibcm_arp_ibd_insts_t *ibdp, sa_family_t family_loc)
508 {
509 #ifdef DEBUG
510 	int i;
511 #endif
512 
513 	IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibds(%p)", ibdp);
514 
515 	ibcm_arp_get_ibd_insts(ibdp);
516 
517 	IBTF_DPRINTF_L3(cmlog, "ibcm_arp_get_ibds: Found %d ibd instances",
518 	    ibdp->ibcm_arp_ibd_cnt);
519 
520 	if (ibdp->ibcm_arp_ibd_cnt == 0)
521 		return (IBT_SRC_IP_NOT_FOUND);
522 
523 	/* Get the IP addresses of active ports. */
524 	if (!ibcm_arp_get_ibd_ipaddr(ibdp, family_loc)) {
525 		IBTF_DPRINTF_L2(cmlog, "ibcm_arp_get_ibds: failed to get "
526 		    "ibd instance: IBT_SRC_IP_NOT_FOUND");
527 		ibcm_arp_free_ibds(ibdp);
528 		return (IBT_SRC_IP_NOT_FOUND);
529 	}
530 
531 #ifdef DEBUG
532 	for (i = 0; i < ibdp->ibcm_arp_ibd_cnt; i++) {
533 		char    my_buf[INET6_ADDRSTRLEN];
534 		ibcm_arp_ip_t	*aip = &ibdp->ibcm_arp_ip[i];
535 
536 		IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibds: Linkid %d Family %d "
537 		    "PKey 0x%lX \n HCAGUID 0x%llX SGID %llX:%llX",
538 		    aip->ip_linkid, aip->ip_inet_family, aip->ip_pkey,
539 		    aip->ip_hca_guid, aip->ip_port_gid.gid_prefix,
540 		    aip->ip_port_gid.gid_guid);
541 		if (aip->ip_inet_family == AF_INET) {
542 			IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibds: IPV4: %s",
543 			    inet_ntop(AF_INET, &aip->ip_cm_sin.sin_addr, my_buf,
544 			    sizeof (my_buf)));
545 		} else if (aip->ip_inet_family == AF_INET6) {
546 			IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibds: IPV6: %s",
547 			    inet_ntop(AF_INET6, &aip->ip_cm_sin6.sin6_addr,
548 			    my_buf, sizeof (my_buf)));
549 		} else {
550 			IBTF_DPRINTF_L2(cmlog, "ibcm_arp_get_ibds: Unknown "
551 			    "Family %d", aip->ip_inet_family);
552 		}
553 	}
554 #endif
555 
556 	return (IBT_SUCCESS);
557 }
558