This source file includes following definitions.
- if_bsdx_ipv6_open
1
2
3
4
5
6
7
8
9
10
11
12
13 #include "opal_config.h"
14 #include "opal/constants.h"
15 #include "opal/util/output.h"
16 #include "opal/util/string_copy.h"
17
18 #include <string.h>
19 #ifdef HAVE_UNISTD_H
20 #include <unistd.h>
21 #endif
22 #include <errno.h>
23 #ifdef HAVE_SYS_TYPES_H
24 #include <sys/types.h>
25 #endif
26 #ifdef HAVE_SYS_SOCKET_H
27 #include <sys/socket.h>
28 #endif
29 #ifdef HAVE_SYS_SOCKIO_H
30 #include <sys/sockio.h>
31 #endif
32 #ifdef HAVE_SYS_IOCTL_H
33 #include <sys/ioctl.h>
34 #endif
35 #ifdef HAVE_NETINET_IN_H
36 #include <netinet/in.h>
37 #endif
38 #ifdef HAVE_ARPA_INET_H
39 #include <arpa/inet.h>
40 #endif
41 #ifdef HAVE_NET_IF_H
42 #include <net/if.h>
43 #endif
44 #ifdef HAVE_NETDB_H
45 #include <netdb.h>
46 #endif
47 #ifdef HAVE_IFADDRS_H
48 #include <ifaddrs.h>
49 #endif
50
51 #include "opal/mca/if/if.h"
52 #include "opal/mca/if/base/base.h"
53
54 static int if_bsdx_ipv6_open(void);
55
56
57
58
59
60
61
62
63
64
65 opal_if_base_component_t mca_if_bsdx_ipv6_component = {
66
67
68 {
69 OPAL_IF_BASE_VERSION_2_0_0,
70
71
72 "bsdx_ipv6",
73 OPAL_MAJOR_VERSION,
74 OPAL_MINOR_VERSION,
75 OPAL_RELEASE_VERSION,
76
77
78 if_bsdx_ipv6_open,
79 NULL
80 },
81 {
82
83 MCA_BASE_METADATA_PARAM_CHECKPOINT
84 },
85 };
86
87
88 static int if_bsdx_ipv6_open(void)
89 {
90 #if OPAL_ENABLE_IPV6
91 struct ifaddrs **ifadd_list;
92 struct ifaddrs *cur_ifaddrs;
93 struct sockaddr_in6* sin_addr;
94
95 opal_output_verbose(1, opal_if_base_framework.framework_output,
96 "searching for IPv6 interfaces");
97
98
99
100
101
102
103 ifadd_list = (struct ifaddrs **) malloc(sizeof(struct ifaddrs*));
104
105
106 if (getifaddrs(ifadd_list) < 0) {
107 opal_output(0, "opal_ifinit: getifaddrs() failed with error=%d\n",
108 errno);
109 free(ifadd_list);
110 return OPAL_ERROR;
111 }
112
113 for (cur_ifaddrs = *ifadd_list; NULL != cur_ifaddrs;
114 cur_ifaddrs = cur_ifaddrs->ifa_next) {
115 opal_if_t *intf;
116 struct in6_addr a6;
117
118
119 if (AF_INET6 != cur_ifaddrs->ifa_addr->sa_family) {
120 opal_output_verbose(1, opal_if_base_framework.framework_output,
121 "skipping non-ipv6 interface %s[%d].\n",
122 cur_ifaddrs->ifa_name, (int)cur_ifaddrs->ifa_addr->sa_family);
123 continue;
124 }
125
126
127 if (0 == (cur_ifaddrs->ifa_flags & IFF_UP)) {
128 opal_output_verbose(1, opal_if_base_framework.framework_output,
129 "skipping non-up interface %s.\n", cur_ifaddrs->ifa_name);
130 continue;
131 }
132
133
134 if (!opal_if_retain_loopback && 0 != (cur_ifaddrs->ifa_flags & IFF_LOOPBACK)) {
135 opal_output_verbose(1, opal_if_base_framework.framework_output,
136 "skipping loopback interface %s.\n", cur_ifaddrs->ifa_name);
137 continue;
138 }
139
140
141
142 if (0!= (cur_ifaddrs->ifa_flags & IFF_POINTOPOINT)) {
143 opal_output_verbose(1, opal_if_base_framework.framework_output,
144 "skipping p2p interface %s.\n", cur_ifaddrs->ifa_name);
145 continue;
146 }
147
148 sin_addr = (struct sockaddr_in6 *) cur_ifaddrs->ifa_addr;
149
150
151
152
153
154
155
156
157
158
159
160
161 if ((IN6_IS_ADDR_LINKLOCAL (&sin_addr->sin6_addr))) {
162 opal_output_verbose(1, opal_if_base_framework.framework_output,
163 "skipping link-local ipv6 address on interface "
164 "%s with scope %d.\n",
165 cur_ifaddrs->ifa_name, sin_addr->sin6_scope_id);
166 continue;
167 }
168
169 if (0 < opal_output_get_verbosity(opal_if_base_framework.framework_output)) {
170 char *addr_name = (char *) malloc(48*sizeof(char));
171 inet_ntop(AF_INET6, &sin_addr->sin6_addr, addr_name, 48*sizeof(char));
172 opal_output(0, "ipv6 capable interface %s discovered, address %s.\n",
173 cur_ifaddrs->ifa_name, addr_name);
174 free(addr_name);
175 }
176
177
178 memcpy(&a6, &(sin_addr->sin6_addr), sizeof(struct in6_addr));
179
180 intf = OBJ_NEW(opal_if_t);
181 if (NULL == intf) {
182 opal_output(0, "opal_ifinit: unable to allocate %lu bytes\n",
183 sizeof(opal_if_t));
184 free(ifadd_list);
185 return OPAL_ERR_OUT_OF_RESOURCE;
186 }
187 intf->af_family = AF_INET6;
188 opal_string_copy(intf->if_name, cur_ifaddrs->ifa_name, IF_NAMESIZE);
189 intf->if_index = opal_list_get_size(&opal_if_list) + 1;
190 ((struct sockaddr_in6*) &intf->if_addr)->sin6_addr = a6;
191 ((struct sockaddr_in6*) &intf->if_addr)->sin6_family = AF_INET6;
192
193
194 ((struct sockaddr_in6*) &intf->if_addr)->sin6_scope_id = 0;
195
196
197
198
199 intf->if_mask = 64;
200 intf->if_flags = cur_ifaddrs->ifa_flags;
201
202
203
204
205
206
207 intf->if_kernel_index =
208 (uint16_t) if_nametoindex(cur_ifaddrs->ifa_name);
209 opal_list_append(&opal_if_list, &(intf->super));
210 }
211
212 free(ifadd_list);
213 #endif
214
215 return OPAL_SUCCESS;
216 }
217
218