diff mbox

[06/16] ibacm: move acm_if_iter_sys to acm_util.c

Message ID 1395985810-23822-7-git-send-email-sean.hefty@intel.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Hefty, Sean March 28, 2014, 5:50 a.m. UTC
From: Ira Weiny <ira.weiny@intel.com>

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 linux/acme_linux.c |   80 ---------------------------------------------------
 src/acm_util.c     |   81 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 80 deletions(-)
diff mbox

Patch

diff --git a/linux/acme_linux.c b/linux/acme_linux.c
index 187507d..33fafd2 100644
--- a/linux/acme_linux.c
+++ b/linux/acme_linux.c
@@ -30,14 +30,6 @@ 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
-#include <arpa/inet.h>
-#include <sys/ioctl.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <errno.h>
 
 #include <infiniband/verbs.h>
 #include "acm_util.h"
@@ -101,75 +93,3 @@  int gen_addr_ip(FILE *f)
 {
 	return acm_if_iter_sys(iter_cb, (void *)f);
 }
-
-int acm_if_iter_sys(acm_if_iter_cb cb, void *ctx)
-{
-	struct ifconf *ifc;
-	struct ifreq *ifr;
-	char ip[INET6_ADDRSTRLEN];
-	int s, ret, i, len;
-	uint16_t pkey;
-	union ibv_gid sgid;
-
-	s = socket(AF_INET6, SOCK_DGRAM, 0);
-	if (!s)
-		return -1;
-
-	len = sizeof(*ifc) + sizeof(*ifr) * 64;
-	ifc = malloc(len);
-	if (!ifc) {
-		ret = -1;
-		goto out1;
-	}
-
-	memset(ifc, 0, len);
-	ifc->ifc_len = len;
-	ifc->ifc_req = (struct ifreq *) (ifc + 1);
-
-	ret = ioctl(s, SIOCGIFCONF, ifc);
-	if (ret < 0) {
-		printf("ioctl ifconf error %d\n", ret);
-		goto out2;
-	}
-
-	ifr = ifc->ifc_req;
-	for (i = 0; i < ifc->ifc_len / sizeof(struct ifreq); i++) {
-		switch (ifr[i].ifr_addr.sa_family) {
-		case AF_INET:
-			inet_ntop(ifr[i].ifr_addr.sa_family,
-				&((struct sockaddr_in *) &ifr[i].ifr_addr)->sin_addr, ip, sizeof ip);
-			break;
-		case AF_INET6:
-			inet_ntop(ifr[i].ifr_addr.sa_family,
-				&((struct sockaddr_in6 *) &ifr[i].ifr_addr)->sin6_addr, ip, sizeof ip);
-			break;
-		default:
-			continue;
-		}
-
-		if (!acm_if_is_ib(ifr[i].ifr_name))
-			continue;
-
-		ret = acm_if_get_sgid(ifr[i].ifr_name, &sgid);
-		if (ret) {
-			printf("unable to get sgid\n");
-			continue;
-		}
-
-		ret = acm_if_get_pkey(ifr[i].ifr_name, &pkey);
-		if (ret) {
-			printf("unable to get pkey\n");
-			continue;
-		}
-
-		cb(ifr[i].ifr_name, &sgid, pkey, 0, NULL, 0, ip, ctx);
-	}
-	ret = 0;
-
-out2:
-	free(ifc);
-out1:
-	close(s);
-	return ret;
-
-}
diff --git a/src/acm_util.c b/src/acm_util.c
index 519735a..922eceb 100644
--- a/src/acm_util.c
+++ b/src/acm_util.c
@@ -30,6 +30,15 @@ 
 #include <stdio.h>
 #include <stdlib.h>
 #include <net/if_arp.h>
+#include <string.h>
+#include <unistd.h>
+#include <arpa/inet.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <errno.h>
 
 #include "acm_util.h"
 
@@ -110,3 +119,75 @@  int acm_if_get_sgid(char *ifname, union ibv_gid *sgid)
 	fclose(f);
 	return ret;
 }
+
+int acm_if_iter_sys(acm_if_iter_cb cb, void *ctx)
+{
+	struct ifconf *ifc;
+	struct ifreq *ifr;
+	char ip[INET6_ADDRSTRLEN];
+	int s, ret, i, len;
+	uint16_t pkey;
+	union ibv_gid sgid;
+
+	s = socket(AF_INET6, SOCK_DGRAM, 0);
+	if (!s)
+		return -1;
+
+	len = sizeof(*ifc) + sizeof(*ifr) * 64;
+	ifc = malloc(len);
+	if (!ifc) {
+		ret = -1;
+		goto out1;
+	}
+
+	memset(ifc, 0, len);
+	ifc->ifc_len = len;
+	ifc->ifc_req = (struct ifreq *) (ifc + 1);
+
+	ret = ioctl(s, SIOCGIFCONF, ifc);
+	if (ret < 0) {
+		printf("ioctl ifconf error %d\n", ret);
+		goto out2;
+	}
+
+	ifr = ifc->ifc_req;
+	for (i = 0; i < ifc->ifc_len / sizeof(struct ifreq); i++) {
+		switch (ifr[i].ifr_addr.sa_family) {
+		case AF_INET:
+			inet_ntop(ifr[i].ifr_addr.sa_family,
+				&((struct sockaddr_in *) &ifr[i].ifr_addr)->sin_addr, ip, sizeof ip);
+			break;
+		case AF_INET6:
+			inet_ntop(ifr[i].ifr_addr.sa_family,
+				&((struct sockaddr_in6 *) &ifr[i].ifr_addr)->sin6_addr, ip, sizeof ip);
+			break;
+		default:
+			continue;
+		}
+
+		if (!acm_if_is_ib(ifr[i].ifr_name))
+			continue;
+
+		ret = acm_if_get_sgid(ifr[i].ifr_name, &sgid);
+		if (ret) {
+			printf("unable to get sgid\n");
+			continue;
+		}
+
+		ret = acm_if_get_pkey(ifr[i].ifr_name, &pkey);
+		if (ret) {
+			printf("unable to get pkey\n");
+			continue;
+		}
+
+		cb(ifr[i].ifr_name, &sgid, pkey, 0, NULL, 0, ip, ctx);
+	}
+	ret = 0;
+
+out2:
+	free(ifc);
+out1:
+	close(s);
+	return ret;
+
+}