@@ -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;
-
-}
@@ -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;
+
+}