totemip.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /*
  2. * Copyright (c) 2005-2007, 2009 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Patrick Caulfield (pcaulfie@redhat.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. /* IPv4/6 abstraction */
  35. #include <config.h>
  36. #include <sys/ioctl.h>
  37. #include <sys/types.h>
  38. #include <sys/socket.h>
  39. #include <arpa/inet.h>
  40. #include <netinet/in.h>
  41. #include <arpa/inet.h>
  42. #include <netdb.h>
  43. #if defined(COROSYNC_SOLARIS)
  44. #include <net/if.h>
  45. #include <sys/sockio.h>
  46. #endif
  47. #if defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN)
  48. #include <sys/sockio.h>
  49. #include <net/if.h>
  50. #include <net/if_var.h>
  51. #include <netinet/in_var.h>
  52. #include <netinet/in.h>
  53. #include <ifaddrs.h>
  54. #endif
  55. #include <string.h>
  56. #include <stdio.h>
  57. #include <errno.h>
  58. #include <assert.h>
  59. #include <stdlib.h>
  60. #include <unistd.h>
  61. #if defined(COROSYNC_LINUX)
  62. #include <net/if.h>
  63. #include <asm/types.h>
  64. #include <linux/rtnetlink.h>
  65. #endif
  66. #include <corosync/totem/totemip.h>
  67. #include <corosync/swab.h>
  68. #define LOCALHOST_IPV4 "127.0.0.1"
  69. #define LOCALHOST_IPV6 "::1"
  70. #define NETLINK_BUFSIZE 16384
  71. #ifdef SO_NOSIGPIPE
  72. void totemip_nosigpipe(int s)
  73. {
  74. int on = 1;
  75. setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (void *)&on, sizeof(on));
  76. }
  77. #endif
  78. /* Compare two addresses */
  79. int totemip_equal(const struct totem_ip_address *addr1,
  80. const struct totem_ip_address *addr2)
  81. {
  82. int addrlen = 0;
  83. if (addr1->family != addr2->family)
  84. return 0;
  85. if (addr1->family == AF_INET) {
  86. addrlen = sizeof(struct in_addr);
  87. }
  88. if (addr1->family == AF_INET6) {
  89. addrlen = sizeof(struct in6_addr);
  90. }
  91. assert(addrlen);
  92. if (memcmp(addr1->addr, addr2->addr, addrlen) == 0)
  93. return 1;
  94. else
  95. return 0;
  96. }
  97. /* Copy a totem_ip_address */
  98. void totemip_copy(struct totem_ip_address *addr1,
  99. const struct totem_ip_address *addr2)
  100. {
  101. memcpy(addr1, addr2, sizeof(struct totem_ip_address));
  102. }
  103. void totemip_copy_endian_convert(struct totem_ip_address *addr1,
  104. const struct totem_ip_address *addr2)
  105. {
  106. addr1->nodeid = swab32(addr2->nodeid);
  107. addr1->family = swab16(addr2->family);
  108. memcpy(addr1->addr, addr2->addr, TOTEMIP_ADDRLEN);
  109. }
  110. /* For sorting etc. params are void * for qsort's benefit */
  111. int totemip_compare(const void *a, const void *b)
  112. {
  113. int i;
  114. const struct totem_ip_address *totemip_a = (const struct totem_ip_address *)a;
  115. const struct totem_ip_address *totemip_b = (const struct totem_ip_address *)b;
  116. struct in_addr ipv4_a1;
  117. struct in_addr ipv4_a2;
  118. struct in6_addr ipv6_a1;
  119. struct in6_addr ipv6_a2;
  120. unsigned short family;
  121. /*
  122. * Use memcpy to align since totem_ip_address is unaligned on various archs
  123. */
  124. memcpy (&family, &totemip_a->family, sizeof (unsigned short));
  125. if (family == AF_INET) {
  126. memcpy (&ipv4_a1, totemip_a->addr, sizeof (struct in_addr));
  127. memcpy (&ipv4_a2, totemip_b->addr, sizeof (struct in_addr));
  128. if (ipv4_a1.s_addr == ipv4_a2.s_addr) {
  129. return (0);
  130. }
  131. if (htonl(ipv4_a1.s_addr) < htonl(ipv4_a2.s_addr)) {
  132. return -1;
  133. } else {
  134. return +1;
  135. }
  136. } else
  137. if (family == AF_INET6) {
  138. /*
  139. * We can only compare 8 bits at time for portability reasons
  140. */
  141. memcpy (&ipv6_a1, totemip_a->addr, sizeof (struct in6_addr));
  142. memcpy (&ipv6_a2, totemip_b->addr, sizeof (struct in6_addr));
  143. for (i = 0; i < 16; i++) {
  144. int res = ipv6_a1.s6_addr[i] -
  145. ipv6_a2.s6_addr[i];
  146. if (res) {
  147. return res;
  148. }
  149. }
  150. return 0;
  151. } else {
  152. /*
  153. * Family not set, should be!
  154. */
  155. assert (0);
  156. }
  157. return 0;
  158. }
  159. /* Build a localhost totem_ip_address */
  160. int totemip_localhost(int family, struct totem_ip_address *localhost)
  161. {
  162. const char *addr_text;
  163. memset (localhost, 0, sizeof (struct totem_ip_address));
  164. if (family == AF_INET) {
  165. addr_text = LOCALHOST_IPV4;
  166. if (inet_pton(family, addr_text, (char *)&localhost->nodeid) <= 0) {
  167. return -1;
  168. }
  169. } else {
  170. addr_text = LOCALHOST_IPV6;
  171. }
  172. if (inet_pton(family, addr_text, (char *)localhost->addr) <= 0)
  173. return -1;
  174. localhost->family = family;
  175. return 0;
  176. }
  177. int totemip_localhost_check(const struct totem_ip_address *addr)
  178. {
  179. struct totem_ip_address localhost;
  180. if (totemip_localhost(addr->family, &localhost))
  181. return 0;
  182. return totemip_equal(addr, &localhost);
  183. }
  184. const char *totemip_print(const struct totem_ip_address *addr)
  185. {
  186. static char buf[INET6_ADDRSTRLEN];
  187. return (inet_ntop(addr->family, addr->addr, buf, sizeof(buf)));
  188. }
  189. /* Make a totem_ip_address into a usable sockaddr_storage */
  190. int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr,
  191. uint16_t port, struct sockaddr_storage *saddr, int *addrlen)
  192. {
  193. int ret = -1;
  194. if (ip_addr->family == AF_INET) {
  195. struct sockaddr_in *sin = (struct sockaddr_in *)saddr;
  196. memset(sin, 0, sizeof(struct sockaddr_in));
  197. #if defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN)
  198. sin->sin_len = sizeof(struct sockaddr_in);
  199. #endif
  200. sin->sin_family = ip_addr->family;
  201. sin->sin_port = ntohs(port);
  202. memcpy(&sin->sin_addr, ip_addr->addr, sizeof(struct in_addr));
  203. *addrlen = sizeof(struct sockaddr_in);
  204. ret = 0;
  205. }
  206. if (ip_addr->family == AF_INET6) {
  207. struct sockaddr_in6 *sin = (struct sockaddr_in6 *)saddr;
  208. memset(sin, 0, sizeof(struct sockaddr_in6));
  209. #if defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN)
  210. sin->sin6_len = sizeof(struct sockaddr_in6);
  211. #endif
  212. sin->sin6_family = ip_addr->family;
  213. sin->sin6_port = ntohs(port);
  214. sin->sin6_scope_id = 2;
  215. memcpy(&sin->sin6_addr, ip_addr->addr, sizeof(struct in6_addr));
  216. *addrlen = sizeof(struct sockaddr_in6);
  217. ret = 0;
  218. }
  219. return ret;
  220. }
  221. /* Converts an address string string into a totem_ip_address.
  222. family can be AF_INET, AF_INET6 or 0 ("for "don't care")
  223. */
  224. int totemip_parse(struct totem_ip_address *totemip, const char *addr, int family)
  225. {
  226. struct addrinfo *ainfo;
  227. struct addrinfo ahints;
  228. struct sockaddr_in *sa;
  229. struct sockaddr_in6 *sa6;
  230. int ret;
  231. memset(&ahints, 0, sizeof(ahints));
  232. ahints.ai_socktype = SOCK_DGRAM;
  233. ahints.ai_protocol = IPPROTO_UDP;
  234. ahints.ai_family = family;
  235. /* Lookup the nodename address */
  236. ret = getaddrinfo(addr, NULL, &ahints, &ainfo);
  237. if (ret)
  238. return -1;
  239. sa = (struct sockaddr_in *)ainfo->ai_addr;
  240. sa6 = (struct sockaddr_in6 *)ainfo->ai_addr;
  241. totemip->family = ainfo->ai_family;
  242. if (ainfo->ai_family == AF_INET)
  243. memcpy(totemip->addr, &sa->sin_addr, sizeof(struct in_addr));
  244. else
  245. memcpy(totemip->addr, &sa6->sin6_addr, sizeof(struct in6_addr));
  246. return 0;
  247. }
  248. /* Make a sockaddr_* into a totem_ip_address */
  249. int totemip_sockaddr_to_totemip_convert(const struct sockaddr_storage *saddr,
  250. struct totem_ip_address *ip_addr)
  251. {
  252. int ret = -1;
  253. ip_addr->family = saddr->ss_family;
  254. ip_addr->nodeid = 0;
  255. if (saddr->ss_family == AF_INET) {
  256. const struct sockaddr_in *sin = (const struct sockaddr_in *)saddr;
  257. memcpy(ip_addr->addr, &sin->sin_addr, sizeof(struct in_addr));
  258. ret = 0;
  259. }
  260. if (saddr->ss_family == AF_INET6) {
  261. const struct sockaddr_in6 *sin
  262. = (const struct sockaddr_in6 *)saddr;
  263. memcpy(ip_addr->addr, &sin->sin6_addr, sizeof(struct in6_addr));
  264. ret = 0;
  265. }
  266. return ret;
  267. }
  268. /*
  269. * On Solaris, man if_tcp describes this method
  270. */
  271. #if defined(COROSYNC_SOLARIS)
  272. int totemip_iface_check(struct totem_ip_address *bindnet,
  273. struct totem_ip_address *boundto,
  274. int *interface_up,
  275. int *interface_num,
  276. int mask_high_bit)
  277. {
  278. struct sockaddr_storage bindnet_ss;
  279. struct sockaddr_in *bindnet_sin = (struct sockaddr_in *)&bindnet_ss;
  280. struct sockaddr_in *sockaddr_in;
  281. int id_fd;
  282. struct lifconf lifconf;
  283. struct lifreq *lifreq;
  284. int numreqs = 0;
  285. int i;
  286. in_addr_t mask_addr;
  287. int res = -1;
  288. int addrlen;
  289. totemip_totemip_to_sockaddr_convert (bindnet,
  290. 0, &bindnet_ss, &addrlen);
  291. *interface_up = 0;
  292. id_fd = socket (AF_INET, SOCK_STREAM, 0);
  293. lifconf.lifc_family = AF_UNSPEC;
  294. lifconf.lifc_flags = 0;
  295. lifconf.lifc_buf = NULL;
  296. lifconf.lifc_len = 0;
  297. do {
  298. numreqs += 32;
  299. lifconf.lifc_len = sizeof (struct lifreq) * numreqs;
  300. lifconf.lifc_buf = (void *)realloc(lifconf.lifc_buf, lifconf.lifc_len);
  301. res = ioctl (id_fd, SIOCGLIFCONF, &lifconf);
  302. if (res < 0) {
  303. close (id_fd);
  304. return -1;
  305. }
  306. } while (lifconf.lifc_len == sizeof (struct lifconf) * numreqs);
  307. res = -1;
  308. lifreq = (struct lifreq *)lifconf.lifc_buf;
  309. /*
  310. * Find interface address to bind to
  311. */
  312. for (i = 0; i < lifconf.lifc_len / sizeof (struct lifreq); i++) {
  313. sockaddr_in = (struct sockaddr_in *)&lifreq[i].lifr_addr;
  314. mask_addr = inet_addr ("255.255.255.0");
  315. if ((sockaddr_in->sin_family == AF_INET) &&
  316. (sockaddr_in->sin_addr.s_addr & mask_addr) ==
  317. (bindnet_sin->sin_addr.s_addr & mask_addr)) {
  318. res = i;
  319. /*
  320. * Setup boundto output
  321. */
  322. totemip_sockaddr_to_totemip_convert(sockaddr_in, boundto);
  323. boundto->nodeid = sockaddr_in->sin_addr.s_addr;
  324. if (ioctl(id_fd, SIOCGLIFFLAGS, &lifreq[i]) < 0) {
  325. printf ("couldn't do ioctl\n");
  326. }
  327. *interface_up = lifreq[i].lifr_flags & IFF_UP;
  328. if (ioctl(id_fd, SIOCGLIFINDEX, &lifreq[i]) < 0) {
  329. printf ("couldn't do ioctl\n");
  330. }
  331. *interface_num = lifreq[i].lifr_index;
  332. break;
  333. }
  334. }
  335. free (lifconf.lifc_buf);
  336. close (id_fd);
  337. return (res);
  338. }
  339. #endif
  340. #if defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN)
  341. int totemip_iface_check(struct totem_ip_address *bindnet,
  342. struct totem_ip_address *boundto,
  343. int *interface_up,
  344. int *interface_num,
  345. int mask_high_bit)
  346. {
  347. #define NEXT_IFR(a) ((struct ifreq *)((u_char *)&(a)->ifr_addr +\
  348. ((a)->ifr_addr.sa_len ? (a)->ifr_addr.sa_len : sizeof((a)->ifr_addr))))
  349. struct sockaddr_in *intf_addr_mask;
  350. struct sockaddr_storage bindnet_ss;
  351. struct sockaddr_in *intf_addr_sin;
  352. struct sockaddr_in *bindnet_sin = (struct sockaddr_in *)&bindnet_ss;
  353. struct ifaddrs *ifap, *ifa;
  354. int res = -1;
  355. int addrlen;
  356. *interface_up = 0;
  357. *interface_num = 0;
  358. totemip_totemip_to_sockaddr_convert(bindnet,
  359. 0, &bindnet_ss, &addrlen);
  360. if (getifaddrs(&ifap) != 0)
  361. return -1;
  362. for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
  363. intf_addr_sin = (struct sockaddr_in *)ifa->ifa_addr;
  364. intf_addr_mask = (struct sockaddr_in *)ifa->ifa_netmask;
  365. if (intf_addr_sin->sin_family != AF_INET)
  366. continue;
  367. if ( bindnet_sin->sin_family == AF_INET &&
  368. (intf_addr_sin->sin_addr.s_addr & intf_addr_mask->sin_addr.s_addr) ==
  369. (bindnet_sin->sin_addr.s_addr & intf_addr_mask->sin_addr.s_addr)) {
  370. totemip_copy(boundto, bindnet);
  371. memcpy(boundto->addr, &intf_addr_sin->sin_addr, sizeof(intf_addr_sin->sin_addr));
  372. /* Get interface infos
  373. */
  374. *interface_up = ifa->ifa_flags & IFF_UP;
  375. *interface_num = if_nametoindex(ifa->ifa_name);
  376. res = 0;
  377. break; /* for */
  378. }
  379. }
  380. freeifaddrs(ifap);
  381. return (res);
  382. }
  383. #elif defined(COROSYNC_LINUX)
  384. static void parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len)
  385. {
  386. while (RTA_OK(rta, len)) {
  387. if (rta->rta_type <= max)
  388. tb[rta->rta_type] = rta;
  389. rta = RTA_NEXT(rta,len);
  390. }
  391. }
  392. int totemip_iface_check(struct totem_ip_address *bindnet,
  393. struct totem_ip_address *boundto,
  394. int *interface_up,
  395. int *interface_num,
  396. int mask_high_bit)
  397. {
  398. int fd;
  399. struct {
  400. struct nlmsghdr nlh;
  401. struct rtgenmsg g;
  402. } req;
  403. struct sockaddr_nl nladdr;
  404. struct totem_ip_address ipaddr;
  405. static char rcvbuf[NETLINK_BUFSIZE];
  406. *interface_up = 0;
  407. *interface_num = 0;
  408. memset(&ipaddr, 0, sizeof(ipaddr));
  409. /* Make sure we preserve these */
  410. ipaddr.family = bindnet->family;
  411. ipaddr.nodeid = bindnet->nodeid;
  412. /* Ask netlink for a list of interface addresses */
  413. fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  414. if (fd <0)
  415. return -1;
  416. setsockopt(fd,SOL_SOCKET,SO_RCVBUF,&rcvbuf,sizeof(rcvbuf));
  417. memset(&nladdr, 0, sizeof(nladdr));
  418. nladdr.nl_family = AF_NETLINK;
  419. memset(&req, 0, sizeof(req));
  420. req.nlh.nlmsg_len = sizeof(req);
  421. req.nlh.nlmsg_type = RTM_GETADDR;
  422. req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
  423. req.nlh.nlmsg_pid = 0;
  424. req.nlh.nlmsg_seq = 1;
  425. req.g.rtgen_family = bindnet->family;
  426. if (sendto(fd, (void *)&req, sizeof(req), 0,
  427. (struct sockaddr*)&nladdr, sizeof(nladdr)) < 0) {
  428. close(fd);
  429. return -1;
  430. }
  431. /* Look through the return buffer for our address */
  432. while (1)
  433. {
  434. int status;
  435. struct nlmsghdr *h;
  436. struct iovec iov = { rcvbuf, sizeof(rcvbuf) };
  437. struct msghdr msg = {
  438. (void*)&nladdr, sizeof(nladdr),
  439. &iov, 1,
  440. NULL, 0,
  441. 0
  442. };
  443. status = recvmsg(fd, &msg, 0);
  444. if (!status) {
  445. close(fd);
  446. return -1;
  447. }
  448. h = (struct nlmsghdr *)rcvbuf;
  449. if (h->nlmsg_type == NLMSG_DONE)
  450. break;
  451. if (h->nlmsg_type == NLMSG_ERROR) {
  452. close(fd);
  453. return -1;
  454. }
  455. while (NLMSG_OK(h, status)) {
  456. if (h->nlmsg_type == RTM_NEWADDR) {
  457. struct ifaddrmsg *ifa = NLMSG_DATA(h);
  458. struct rtattr *tb[IFA_MAX+1];
  459. int len = h->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa));
  460. int found_if = 0;
  461. memset(tb, 0, sizeof(tb));
  462. parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), len);
  463. memcpy(ipaddr.addr, RTA_DATA(tb[IFA_ADDRESS]), TOTEMIP_ADDRLEN);
  464. if (totemip_equal(&ipaddr, bindnet)) {
  465. found_if = 1;
  466. }
  467. /* If the address we have is an IPv4 network address, then
  468. substitute the actual IP address of this interface */
  469. if (!found_if && tb[IFA_BROADCAST] && ifa->ifa_family == AF_INET) {
  470. uint32_t network;
  471. uint32_t addr;
  472. uint32_t netmask = htonl(~((1<<(32-ifa->ifa_prefixlen))-1));
  473. memcpy(&network, RTA_DATA(tb[IFA_BROADCAST]), sizeof(uint32_t));
  474. memcpy(&addr, bindnet->addr, sizeof(uint32_t));
  475. if ((addr & netmask) == (network & netmask)) {
  476. memcpy(ipaddr.addr, RTA_DATA(tb[IFA_ADDRESS]), TOTEMIP_ADDRLEN);
  477. found_if = 1;
  478. }
  479. }
  480. if (found_if) {
  481. /* Found it - check I/F is UP */
  482. struct ifreq ifr;
  483. int ioctl_fd; /* Can't do ioctls on netlink FDs */
  484. ioctl_fd = socket(AF_INET, SOCK_STREAM, 0);
  485. if (ioctl_fd < 0) {
  486. close(fd);
  487. return -1;
  488. }
  489. memset(&ifr, 0, sizeof(ifr));
  490. ifr.ifr_ifindex = ifa->ifa_index;
  491. /* SIOCGIFFLAGS needs an interface name */
  492. status = ioctl(ioctl_fd, SIOCGIFNAME, &ifr);
  493. status = ioctl(ioctl_fd, SIOCGIFFLAGS, &ifr);
  494. if (status) {
  495. close(ioctl_fd);
  496. close(fd);
  497. return -1;
  498. }
  499. if (ifr.ifr_flags & IFF_UP)
  500. *interface_up = 1;
  501. *interface_num = ifa->ifa_index;
  502. close(ioctl_fd);
  503. goto finished;
  504. }
  505. }
  506. h = NLMSG_NEXT(h, status);
  507. }
  508. }
  509. finished:
  510. /*
  511. * Mask 32nd bit off to workaround bugs in other poeples code
  512. * if configuration requests it.
  513. */
  514. if (ipaddr.family == AF_INET && ipaddr.nodeid == 0) {
  515. unsigned int nodeid = 0;
  516. memcpy (&nodeid, ipaddr.addr, sizeof (int));
  517. if (mask_high_bit) {
  518. nodeid &= 0x7FFFFFFF;
  519. }
  520. ipaddr.nodeid = nodeid;
  521. }
  522. totemip_copy (boundto, &ipaddr);
  523. close(fd);
  524. return 0;
  525. }
  526. #endif /* COROSYNC_LINUX */