totemudpu.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424
  1. /*
  2. * Copyright (c) 2005 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2018 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@redhat.com)
  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. #include <config.h>
  35. #include <assert.h>
  36. #include <sys/mman.h>
  37. #include <sys/types.h>
  38. #include <sys/stat.h>
  39. #include <sys/socket.h>
  40. #include <netdb.h>
  41. #include <sys/un.h>
  42. #include <sys/ioctl.h>
  43. #include <sys/param.h>
  44. #include <netinet/in.h>
  45. #include <arpa/inet.h>
  46. #include <unistd.h>
  47. #include <fcntl.h>
  48. #include <stdlib.h>
  49. #include <stdio.h>
  50. #include <errno.h>
  51. #include <sched.h>
  52. #include <time.h>
  53. #include <sys/time.h>
  54. #include <sys/poll.h>
  55. #include <sys/uio.h>
  56. #include <limits.h>
  57. #include <qb/qblist.h>
  58. #include <qb/qbdefs.h>
  59. #include <qb/qbloop.h>
  60. #include <corosync/sq.h>
  61. #include <corosync/swab.h>
  62. #define LOGSYS_UTILS_ONLY 1
  63. #include <corosync/logsys.h>
  64. #include "totemudpu.h"
  65. #include "util.h"
  66. #ifndef MSG_NOSIGNAL
  67. #define MSG_NOSIGNAL 0
  68. #endif
  69. #define MCAST_SOCKET_BUFFER_SIZE (TRANSMITS_ALLOWED * UDP_RECEIVE_FRAME_SIZE_MAX)
  70. #define NETIF_STATE_REPORT_UP 1
  71. #define NETIF_STATE_REPORT_DOWN 2
  72. #define BIND_STATE_UNBOUND 0
  73. #define BIND_STATE_REGULAR 1
  74. #define BIND_STATE_LOOPBACK 2
  75. struct totemudpu_member {
  76. struct qb_list_head list;
  77. struct totem_ip_address member;
  78. int fd;
  79. int active;
  80. };
  81. struct totemudpu_instance {
  82. qb_loop_t *totemudpu_poll_handle;
  83. struct totem_interface *totem_interface;
  84. int netif_state_report;
  85. int netif_bind_state;
  86. void *context;
  87. void (*totemudpu_deliver_fn) (
  88. void *context,
  89. const void *msg,
  90. unsigned int msg_len,
  91. const struct sockaddr_storage *system_from);
  92. void (*totemudpu_iface_change_fn) (
  93. void *context,
  94. const struct totem_ip_address *iface_address,
  95. unsigned int ring_no);
  96. void (*totemudpu_target_set_completed) (void *context);
  97. /*
  98. * Function and data used to log messages
  99. */
  100. int totemudpu_log_level_security;
  101. int totemudpu_log_level_error;
  102. int totemudpu_log_level_warning;
  103. int totemudpu_log_level_notice;
  104. int totemudpu_log_level_debug;
  105. int totemudpu_subsys_id;
  106. void (*totemudpu_log_printf) (
  107. int level,
  108. int subsys,
  109. const char *function,
  110. const char *file,
  111. int line,
  112. const char *format,
  113. ...)__attribute__((format(printf, 6, 7)));
  114. void *udpu_context;
  115. char iov_buffer[UDP_RECEIVE_FRAME_SIZE_MAX];
  116. struct iovec totemudpu_iov_recv;
  117. struct qb_list_head member_list;
  118. int stats_sent;
  119. int stats_recv;
  120. int stats_delv;
  121. int stats_remcasts;
  122. int stats_orf_token;
  123. struct timeval stats_tv_start;
  124. struct totem_ip_address my_id;
  125. int firstrun;
  126. qb_loop_timer_handle timer_netif_check_timeout;
  127. unsigned int my_memb_entries;
  128. struct totem_config *totem_config;
  129. totemsrp_stats_t *stats;
  130. struct totem_ip_address token_target;
  131. int token_socket;
  132. int local_loop_sock[2];
  133. qb_loop_timer_handle timer_merge_detect_timeout;
  134. int send_merge_detect_message;
  135. unsigned int merge_detect_messages_sent_before_timeout;
  136. };
  137. struct work_item {
  138. const void *msg;
  139. unsigned int msg_len;
  140. struct totemudpu_instance *instance;
  141. };
  142. static int totemudpu_build_sockets (
  143. struct totemudpu_instance *instance,
  144. struct totem_ip_address *bindnet_address,
  145. struct totem_ip_address *bound_to);
  146. static int totemudpu_create_sending_socket(
  147. void *udpu_context,
  148. const struct totem_ip_address *member);
  149. int totemudpu_member_list_rebind_ip (
  150. void *udpu_context);
  151. static void totemudpu_start_merge_detect_timeout(
  152. void *udpu_context);
  153. static void totemudpu_stop_merge_detect_timeout(
  154. void *udpu_context);
  155. static void totemudpu_instance_initialize (struct totemudpu_instance *instance)
  156. {
  157. memset (instance, 0, sizeof (struct totemudpu_instance));
  158. instance->netif_state_report = NETIF_STATE_REPORT_UP | NETIF_STATE_REPORT_DOWN;
  159. instance->totemudpu_iov_recv.iov_base = instance->iov_buffer;
  160. instance->totemudpu_iov_recv.iov_len = UDP_RECEIVE_FRAME_SIZE_MAX; //sizeof (instance->iov_buffer);
  161. /*
  162. * There is always atleast 1 processor
  163. */
  164. instance->my_memb_entries = 1;
  165. qb_list_init (&instance->member_list);
  166. }
  167. #define log_printf(level, format, args...) \
  168. do { \
  169. instance->totemudpu_log_printf ( \
  170. level, instance->totemudpu_subsys_id, \
  171. __FUNCTION__, __FILE__, __LINE__, \
  172. (const char *)format, ##args); \
  173. } while (0);
  174. #define LOGSYS_PERROR(err_num, level, fmt, args...) \
  175. do { \
  176. char _error_str[LOGSYS_MAX_PERROR_MSG_LEN]; \
  177. const char *_error_ptr = qb_strerror_r(err_num, _error_str, sizeof(_error_str)); \
  178. instance->totemudpu_log_printf ( \
  179. level, instance->totemudpu_subsys_id, \
  180. __FUNCTION__, __FILE__, __LINE__, \
  181. fmt ": %s (%d)", ##args, _error_ptr, err_num); \
  182. } while(0)
  183. int totemudpu_crypto_set (
  184. void *udpu_context,
  185. const char *cipher_type,
  186. const char *hash_type)
  187. {
  188. return (0);
  189. }
  190. static inline void ucast_sendmsg (
  191. struct totemudpu_instance *instance,
  192. struct totem_ip_address *system_to,
  193. const void *msg,
  194. unsigned int msg_len)
  195. {
  196. struct msghdr msg_ucast;
  197. int res = 0;
  198. struct sockaddr_storage sockaddr;
  199. struct iovec iovec;
  200. int addrlen;
  201. int send_sock;
  202. iovec.iov_base = (void *)msg;
  203. iovec.iov_len = msg_len;
  204. /*
  205. * Build unicast message
  206. */
  207. totemip_totemip_to_sockaddr_convert(system_to,
  208. instance->totem_interface->ip_port, &sockaddr, &addrlen);
  209. memset(&msg_ucast, 0, sizeof(msg_ucast));
  210. msg_ucast.msg_name = &sockaddr;
  211. msg_ucast.msg_namelen = addrlen;
  212. msg_ucast.msg_iov = (void *)&iovec;
  213. msg_ucast.msg_iovlen = 1;
  214. #ifdef HAVE_MSGHDR_CONTROL
  215. msg_ucast.msg_control = 0;
  216. #endif
  217. #ifdef HAVE_MSGHDR_CONTROLLEN
  218. msg_ucast.msg_controllen = 0;
  219. #endif
  220. #ifdef HAVE_MSGHDR_FLAGS
  221. msg_ucast.msg_flags = 0;
  222. #endif
  223. #ifdef HAVE_MSGHDR_ACCRIGHTS
  224. msg_ucast.msg_accrights = NULL;
  225. #endif
  226. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  227. msg_ucast.msg_accrightslen = 0;
  228. #endif
  229. if (instance->netif_bind_state == BIND_STATE_REGULAR) {
  230. send_sock = instance->token_socket;
  231. } else {
  232. send_sock = instance->local_loop_sock[1];
  233. msg_ucast.msg_name = NULL;
  234. msg_ucast.msg_namelen = 0;
  235. }
  236. /*
  237. * Transmit unicast message
  238. * An error here is recovered by totemsrp
  239. */
  240. res = sendmsg (send_sock, &msg_ucast, MSG_NOSIGNAL);
  241. if (res < 0) {
  242. LOGSYS_PERROR (errno, instance->totemudpu_log_level_debug,
  243. "sendmsg(ucast) failed (non-critical)");
  244. }
  245. }
  246. static inline void mcast_sendmsg (
  247. struct totemudpu_instance *instance,
  248. const void *msg,
  249. unsigned int msg_len,
  250. int only_active)
  251. {
  252. struct msghdr msg_mcast;
  253. int res = 0;
  254. struct iovec iovec;
  255. struct sockaddr_storage sockaddr;
  256. int addrlen;
  257. struct qb_list_head *list;
  258. struct totemudpu_member *member;
  259. iovec.iov_base = (void *)msg;
  260. iovec.iov_len = msg_len;
  261. memset(&msg_mcast, 0, sizeof(msg_mcast));
  262. /*
  263. * Build multicast message
  264. */
  265. if (instance->netif_bind_state == BIND_STATE_REGULAR) {
  266. qb_list_for_each(list, &(instance->member_list)) {
  267. member = qb_list_entry (list,
  268. struct totemudpu_member,
  269. list);
  270. /*
  271. * Do not send multicast message if message is not "flush", member
  272. * is inactive and timeout for sending merge message didn't expired.
  273. */
  274. if (only_active && !member->active && !instance->send_merge_detect_message)
  275. continue ;
  276. totemip_totemip_to_sockaddr_convert(&member->member,
  277. instance->totem_interface->ip_port, &sockaddr, &addrlen);
  278. msg_mcast.msg_name = &sockaddr;
  279. msg_mcast.msg_namelen = addrlen;
  280. msg_mcast.msg_iov = (void *)&iovec;
  281. msg_mcast.msg_iovlen = 1;
  282. #ifdef HAVE_MSGHDR_CONTROL
  283. msg_mcast.msg_control = 0;
  284. #endif
  285. #ifdef HAVE_MSGHDR_CONTROLLEN
  286. msg_mcast.msg_controllen = 0;
  287. #endif
  288. #ifdef HAVE_MSGHDR_FLAGS
  289. msg_mcast.msg_flags = 0;
  290. #endif
  291. #ifdef HAVE_MSGHDR_ACCRIGHTS
  292. msg_mcast.msg_accrights = NULL;
  293. #endif
  294. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  295. msg_mcast.msg_accrightslen = 0;
  296. #endif
  297. /*
  298. * Transmit multicast message
  299. * An error here is recovered by totemsrp
  300. */
  301. res = sendmsg (member->fd, &msg_mcast, MSG_NOSIGNAL);
  302. if (res < 0) {
  303. LOGSYS_PERROR (errno, instance->totemudpu_log_level_debug,
  304. "sendmsg(mcast) failed (non-critical)");
  305. }
  306. }
  307. if (!only_active || instance->send_merge_detect_message) {
  308. /*
  309. * Current message was sent to all nodes
  310. */
  311. instance->merge_detect_messages_sent_before_timeout++;
  312. instance->send_merge_detect_message = 0;
  313. }
  314. } else {
  315. /*
  316. * Transmit multicast message to local unix mcast loop
  317. * An error here is recovered by totemsrp
  318. */
  319. msg_mcast.msg_name = NULL;
  320. msg_mcast.msg_namelen = 0;
  321. msg_mcast.msg_iov = (void *)&iovec;
  322. msg_mcast.msg_iovlen = 1;
  323. #ifdef HAVE_MSGHDR_CONTROL
  324. msg_mcast.msg_control = 0;
  325. #endif
  326. #ifdef HAVE_MSGHDR_CONTROLLEN
  327. msg_mcast.msg_controllen = 0;
  328. #endif
  329. #ifdef HAVE_MSGHDR_FLAGS
  330. msg_mcast.msg_flags = 0;
  331. #endif
  332. #ifdef HAVE_MSGHDR_ACCRIGHTS
  333. msg_mcast.msg_accrights = NULL;
  334. #endif
  335. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  336. msg_mcast.msg_accrightslen = 0;
  337. #endif
  338. res = sendmsg (instance->local_loop_sock[1], &msg_mcast,
  339. MSG_NOSIGNAL);
  340. if (res < 0) {
  341. LOGSYS_PERROR (errno, instance->totemudpu_log_level_debug,
  342. "sendmsg(local mcast loop) failed (non-critical)");
  343. }
  344. }
  345. }
  346. int totemudpu_finalize (
  347. void *udpu_context)
  348. {
  349. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  350. int res = 0;
  351. if (instance->token_socket > 0) {
  352. qb_loop_poll_del (instance->totemudpu_poll_handle,
  353. instance->token_socket);
  354. close (instance->token_socket);
  355. }
  356. if (instance->local_loop_sock[0] > 0) {
  357. qb_loop_poll_del (instance->totemudpu_poll_handle,
  358. instance->local_loop_sock[0]);
  359. close (instance->local_loop_sock[0]);
  360. close (instance->local_loop_sock[1]);
  361. }
  362. totemudpu_stop_merge_detect_timeout(instance);
  363. return (res);
  364. }
  365. static struct totemudpu_member *find_member_by_sockaddr(
  366. const void *udpu_context,
  367. const struct sockaddr *sa)
  368. {
  369. struct qb_list_head *list;
  370. struct totemudpu_member *member;
  371. struct totemudpu_member *res_member;
  372. const struct totemudpu_instance *instance = (const struct totemudpu_instance *)udpu_context;
  373. res_member = NULL;
  374. qb_list_for_each(list, &(instance->member_list)) {
  375. member = qb_list_entry (list,
  376. struct totemudpu_member,
  377. list);
  378. if (totemip_sa_equal(&member->member, sa)) {
  379. res_member = member;
  380. break ;
  381. }
  382. }
  383. return (res_member);
  384. }
  385. static int net_deliver_fn (
  386. int fd,
  387. int revents,
  388. void *data)
  389. {
  390. struct totemudpu_instance *instance = (struct totemudpu_instance *)data;
  391. struct msghdr msg_recv;
  392. struct iovec *iovec;
  393. struct sockaddr_storage system_from;
  394. int bytes_received;
  395. int truncated_packet;
  396. iovec = &instance->totemudpu_iov_recv;
  397. /*
  398. * Receive datagram
  399. */
  400. msg_recv.msg_name = &system_from;
  401. msg_recv.msg_namelen = sizeof (struct sockaddr_storage);
  402. msg_recv.msg_iov = iovec;
  403. msg_recv.msg_iovlen = 1;
  404. #ifdef HAVE_MSGHDR_CONTROL
  405. msg_recv.msg_control = 0;
  406. #endif
  407. #ifdef HAVE_MSGHDR_CONTROLLEN
  408. msg_recv.msg_controllen = 0;
  409. #endif
  410. #ifdef HAVE_MSGHDR_FLAGS
  411. msg_recv.msg_flags = 0;
  412. #endif
  413. #ifdef HAVE_MSGHDR_ACCRIGHTS
  414. msg_recv.msg_accrights = NULL;
  415. #endif
  416. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  417. msg_recv.msg_accrightslen = 0;
  418. #endif
  419. bytes_received = recvmsg (fd, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT);
  420. if (bytes_received == -1) {
  421. return (0);
  422. } else {
  423. instance->stats_recv += bytes_received;
  424. }
  425. truncated_packet = 0;
  426. #ifdef HAVE_MSGHDR_FLAGS
  427. if (msg_recv.msg_flags & MSG_TRUNC) {
  428. truncated_packet = 1;
  429. }
  430. #else
  431. /*
  432. * We don't have MSGHDR_FLAGS, but we can (hopefully) safely make assumption that
  433. * if bytes_received == UDP_RECEIVE_FRAME_SIZE_MAX then packet is truncated
  434. */
  435. if (bytes_received == UDP_RECEIVE_FRAME_SIZE_MAX) {
  436. truncated_packet = 1;
  437. }
  438. #endif
  439. if (truncated_packet) {
  440. log_printf (instance->totemudpu_log_level_error,
  441. "Received too big message. This may be because something bad is happening"
  442. "on the network (attack?), or you tried join more nodes than corosync is"
  443. "compiled with (%u) or bug in the code (bad estimation of "
  444. "the UDP_RECEIVE_FRAME_SIZE_MAX). Dropping packet.", PROCESSOR_COUNT_MAX);
  445. return (0);
  446. }
  447. if (instance->totem_config->block_unlisted_ips &&
  448. find_member_by_sockaddr(instance, (const struct sockaddr *)&system_from) == NULL) {
  449. log_printf(instance->totemudpu_log_level_debug, "Packet rejected from %s",
  450. totemip_sa_print((const struct sockaddr *)&system_from));
  451. return (0);
  452. }
  453. iovec->iov_len = bytes_received;
  454. /*
  455. * Handle incoming message
  456. */
  457. instance->totemudpu_deliver_fn (
  458. instance->context,
  459. iovec->iov_base,
  460. iovec->iov_len,
  461. &system_from);
  462. iovec->iov_len = UDP_RECEIVE_FRAME_SIZE_MAX;
  463. return (0);
  464. }
  465. static int netif_determine (
  466. struct totemudpu_instance *instance,
  467. struct totem_ip_address *bindnet,
  468. struct totem_ip_address *bound_to,
  469. int *interface_up,
  470. int *interface_num)
  471. {
  472. int res;
  473. res = totemip_iface_check (bindnet, bound_to,
  474. interface_up, interface_num,
  475. instance->totem_config->clear_node_high_bit);
  476. return (res);
  477. }
  478. /*
  479. * If the interface is up, the sockets for totem are built. If the interface is down
  480. * this function is requeued in the timer list to retry building the sockets later.
  481. */
  482. static void timer_function_netif_check_timeout (
  483. void *data)
  484. {
  485. struct totemudpu_instance *instance = (struct totemudpu_instance *)data;
  486. int interface_up;
  487. int interface_num;
  488. /*
  489. * Build sockets for every interface
  490. */
  491. netif_determine (instance,
  492. &instance->totem_interface->bindnet,
  493. &instance->totem_interface->boundto,
  494. &interface_up, &interface_num);
  495. /*
  496. * If the network interface isn't back up and we are already
  497. * in loopback mode, add timer to check again and return
  498. */
  499. if ((instance->netif_bind_state == BIND_STATE_LOOPBACK &&
  500. interface_up == 0) ||
  501. (instance->my_memb_entries == 1 &&
  502. instance->netif_bind_state == BIND_STATE_REGULAR &&
  503. interface_up == 1)) {
  504. qb_loop_timer_add (instance->totemudpu_poll_handle,
  505. QB_LOOP_MED,
  506. instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
  507. (void *)instance,
  508. timer_function_netif_check_timeout,
  509. &instance->timer_netif_check_timeout);
  510. /*
  511. * Add a timer to check for a downed regular interface
  512. */
  513. return;
  514. }
  515. if (instance->token_socket > 0) {
  516. qb_loop_poll_del (instance->totemudpu_poll_handle,
  517. instance->token_socket);
  518. close (instance->token_socket);
  519. instance->token_socket = -1;
  520. }
  521. if (interface_up == 0) {
  522. if (instance->netif_bind_state == BIND_STATE_UNBOUND) {
  523. log_printf (instance->totemudpu_log_level_error,
  524. "One of your ip addresses are now bound to localhost. "
  525. "Corosync would not work correctly.");
  526. exit(COROSYNC_DONE_FATAL_ERR);
  527. }
  528. /*
  529. * Interface is not up
  530. */
  531. instance->netif_bind_state = BIND_STATE_LOOPBACK;
  532. /*
  533. * Add a timer to retry building interfaces and request memb_gather_enter
  534. */
  535. qb_loop_timer_add (instance->totemudpu_poll_handle,
  536. QB_LOOP_MED,
  537. instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
  538. (void *)instance,
  539. timer_function_netif_check_timeout,
  540. &instance->timer_netif_check_timeout);
  541. } else {
  542. /*
  543. * Interface is up
  544. */
  545. instance->netif_bind_state = BIND_STATE_REGULAR;
  546. }
  547. /*
  548. * Create and bind the multicast and unicast sockets
  549. */
  550. totemudpu_build_sockets (instance,
  551. &instance->totem_interface->bindnet,
  552. &instance->totem_interface->boundto);
  553. if (instance->netif_bind_state == BIND_STATE_REGULAR) {
  554. qb_loop_poll_add (instance->totemudpu_poll_handle,
  555. QB_LOOP_MED,
  556. instance->token_socket,
  557. POLLIN, instance, net_deliver_fn);
  558. }
  559. totemip_copy (&instance->my_id, &instance->totem_interface->boundto);
  560. /*
  561. * This reports changes in the interface to the user and totemsrp
  562. */
  563. if (instance->netif_bind_state == BIND_STATE_REGULAR) {
  564. if (instance->netif_state_report & NETIF_STATE_REPORT_UP) {
  565. log_printf (instance->totemudpu_log_level_notice,
  566. "The network interface [%s] is now up.",
  567. totemip_print (&instance->totem_interface->boundto));
  568. instance->netif_state_report = NETIF_STATE_REPORT_DOWN;
  569. instance->totemudpu_iface_change_fn (instance->context, &instance->my_id, 0);
  570. }
  571. /*
  572. * Add a timer to check for interface going down in single membership
  573. */
  574. if (instance->my_memb_entries == 1) {
  575. qb_loop_timer_add (instance->totemudpu_poll_handle,
  576. QB_LOOP_MED,
  577. instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
  578. (void *)instance,
  579. timer_function_netif_check_timeout,
  580. &instance->timer_netif_check_timeout);
  581. }
  582. } else {
  583. if (instance->netif_state_report & NETIF_STATE_REPORT_DOWN) {
  584. log_printf (instance->totemudpu_log_level_notice,
  585. "The network interface is down.");
  586. instance->totemudpu_iface_change_fn (instance->context, &instance->my_id, 0);
  587. }
  588. instance->netif_state_report = NETIF_STATE_REPORT_UP;
  589. }
  590. }
  591. /* Set the socket priority to INTERACTIVE to ensure
  592. that our messages don't get queued behind anything else */
  593. static void totemudpu_traffic_control_set(struct totemudpu_instance *instance, int sock)
  594. {
  595. #ifdef SO_PRIORITY
  596. int prio = 6; /* TC_PRIO_INTERACTIVE */
  597. if (setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(int))) {
  598. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  599. "Could not set traffic priority");
  600. }
  601. #endif
  602. }
  603. static int totemudpu_build_sockets_ip (
  604. struct totemudpu_instance *instance,
  605. struct totem_ip_address *bindnet_address,
  606. struct totem_ip_address *bound_to,
  607. int interface_num)
  608. {
  609. struct sockaddr_storage sockaddr;
  610. int addrlen;
  611. int res;
  612. unsigned int recvbuf_size;
  613. unsigned int optlen = sizeof (recvbuf_size);
  614. unsigned int retries = 0;
  615. /*
  616. * Setup unicast socket
  617. */
  618. instance->token_socket = socket (bindnet_address->family, SOCK_DGRAM, 0);
  619. if (instance->token_socket == -1) {
  620. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  621. "socket() failed");
  622. return (-1);
  623. }
  624. totemip_nosigpipe (instance->token_socket);
  625. res = fcntl (instance->token_socket, F_SETFL, O_NONBLOCK);
  626. if (res == -1) {
  627. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  628. "Could not set non-blocking operation on token socket");
  629. return (-1);
  630. }
  631. /*
  632. * Bind to unicast socket used for token send/receives
  633. * This has the side effect of binding to the correct interface
  634. */
  635. totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_interface->ip_port, &sockaddr, &addrlen);
  636. while (1) {
  637. res = bind (instance->token_socket, (struct sockaddr *)&sockaddr, addrlen);
  638. if (res == 0) {
  639. break;
  640. }
  641. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  642. "bind token socket failed");
  643. if (++retries > BIND_MAX_RETRIES) {
  644. break;
  645. }
  646. /*
  647. * Wait for a while
  648. */
  649. (void)poll(NULL, 0, BIND_RETRIES_INTERVAL * retries);
  650. }
  651. if (res == -1) {
  652. return (-1);
  653. }
  654. /*
  655. * the token_socket can receive many messages. Allow a large number
  656. * of receive messages on this socket
  657. */
  658. recvbuf_size = MCAST_SOCKET_BUFFER_SIZE;
  659. res = setsockopt (instance->token_socket, SOL_SOCKET, SO_RCVBUF,
  660. &recvbuf_size, optlen);
  661. if (res == -1) {
  662. LOGSYS_PERROR (errno, instance->totemudpu_log_level_notice,
  663. "Could not set recvbuf size");
  664. }
  665. return 0;
  666. }
  667. int totemudpu_ifaces_get (
  668. void *net_context,
  669. char ***status,
  670. unsigned int *iface_count)
  671. {
  672. static char *statuses[INTERFACE_MAX] = {(char*)"OK"};
  673. if (status) {
  674. *status = statuses;
  675. }
  676. *iface_count = 1;
  677. return (0);
  678. }
  679. static int totemudpu_build_local_sockets(
  680. struct totemudpu_instance *instance)
  681. {
  682. int i;
  683. unsigned int sendbuf_size;
  684. unsigned int recvbuf_size;
  685. unsigned int optlen = sizeof (sendbuf_size);
  686. int res;
  687. /*
  688. * Create local multicast loop socket
  689. */
  690. if (socketpair(AF_UNIX, SOCK_DGRAM, 0, instance->local_loop_sock) == -1) {
  691. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  692. "socket() failed");
  693. return (-1);
  694. }
  695. for (i = 0; i < 2; i++) {
  696. totemip_nosigpipe (instance->local_loop_sock[i]);
  697. res = fcntl (instance->local_loop_sock[i], F_SETFL, O_NONBLOCK);
  698. if (res == -1) {
  699. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  700. "Could not set non-blocking operation on multicast socket");
  701. return (-1);
  702. }
  703. }
  704. recvbuf_size = MCAST_SOCKET_BUFFER_SIZE;
  705. sendbuf_size = MCAST_SOCKET_BUFFER_SIZE;
  706. res = setsockopt (instance->local_loop_sock[0], SOL_SOCKET, SO_RCVBUF, &recvbuf_size, optlen);
  707. if (res == -1) {
  708. LOGSYS_PERROR (errno, instance->totemudpu_log_level_debug,
  709. "Unable to set SO_RCVBUF size on UDP local mcast loop socket");
  710. return (-1);
  711. }
  712. res = setsockopt (instance->local_loop_sock[1], SOL_SOCKET, SO_SNDBUF, &sendbuf_size, optlen);
  713. if (res == -1) {
  714. LOGSYS_PERROR (errno, instance->totemudpu_log_level_debug,
  715. "Unable to set SO_SNDBUF size on UDP local mcast loop socket");
  716. return (-1);
  717. }
  718. res = getsockopt (instance->local_loop_sock[0], SOL_SOCKET, SO_RCVBUF, &recvbuf_size, &optlen);
  719. if (res == 0) {
  720. log_printf (instance->totemudpu_log_level_debug,
  721. "Local receive multicast loop socket recv buffer size (%d bytes).", recvbuf_size);
  722. }
  723. res = getsockopt (instance->local_loop_sock[1], SOL_SOCKET, SO_SNDBUF, &sendbuf_size, &optlen);
  724. if (res == 0) {
  725. log_printf (instance->totemudpu_log_level_debug,
  726. "Local transmit multicast loop socket send buffer size (%d bytes).", sendbuf_size);
  727. }
  728. return (0);
  729. }
  730. static int totemudpu_build_sockets (
  731. struct totemudpu_instance *instance,
  732. struct totem_ip_address *bindnet_address,
  733. struct totem_ip_address *bound_to)
  734. {
  735. int interface_num;
  736. int interface_up;
  737. int res;
  738. /*
  739. * Determine the ip address bound to and the interface name
  740. */
  741. res = netif_determine (instance,
  742. bindnet_address,
  743. bound_to,
  744. &interface_up,
  745. &interface_num);
  746. if (res == -1) {
  747. return (-1);
  748. }
  749. totemip_copy(&instance->my_id, bound_to);
  750. res = totemudpu_build_sockets_ip (instance,
  751. bindnet_address, bound_to, interface_num);
  752. if (res == -1) {
  753. /* if we get here, corosync won't work anyway, so better leaving than faking to work */
  754. LOGSYS_PERROR (errno, instance->totemudpu_log_level_error,
  755. "Unable to create sockets, exiting");
  756. exit(EXIT_FAILURE);
  757. }
  758. /* We only send out of the token socket */
  759. totemudpu_traffic_control_set(instance, instance->token_socket);
  760. /*
  761. * Rebind all members to new ips
  762. */
  763. totemudpu_member_list_rebind_ip(instance);
  764. return res;
  765. }
  766. /*
  767. * Totem Network interface
  768. * depends on poll abstraction, POSIX, IPV4
  769. */
  770. /*
  771. * Create an instance
  772. */
  773. int totemudpu_initialize (
  774. qb_loop_t *poll_handle,
  775. void **udpu_context,
  776. struct totem_config *totem_config,
  777. totemsrp_stats_t *stats,
  778. void *context,
  779. void (*deliver_fn) (
  780. void *context,
  781. const void *msg,
  782. unsigned int msg_len,
  783. const struct sockaddr_storage *system_from),
  784. void (*iface_change_fn) (
  785. void *context,
  786. const struct totem_ip_address *iface_address,
  787. unsigned int ring_no),
  788. void (*mtu_changed) (
  789. void *context,
  790. int net_mtu),
  791. void (*target_set_completed) (
  792. void *context))
  793. {
  794. struct totemudpu_instance *instance;
  795. instance = malloc (sizeof (struct totemudpu_instance));
  796. if (instance == NULL) {
  797. return (-1);
  798. }
  799. totemudpu_instance_initialize (instance);
  800. instance->totem_config = totem_config;
  801. instance->stats = stats;
  802. /*
  803. * Configure logging
  804. */
  805. instance->totemudpu_log_level_security = 1; //totem_config->totem_logging_configuration.log_level_security;
  806. instance->totemudpu_log_level_error = totem_config->totem_logging_configuration.log_level_error;
  807. instance->totemudpu_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
  808. instance->totemudpu_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
  809. instance->totemudpu_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
  810. instance->totemudpu_subsys_id = totem_config->totem_logging_configuration.log_subsys_id;
  811. instance->totemudpu_log_printf = totem_config->totem_logging_configuration.log_printf;
  812. /*
  813. * Initialize local variables for totemudpu
  814. */
  815. instance->totem_interface = &totem_config->interfaces[0];
  816. memset (instance->iov_buffer, 0, UDP_RECEIVE_FRAME_SIZE_MAX);
  817. instance->totemudpu_poll_handle = poll_handle;
  818. instance->totem_interface->bindnet.nodeid = instance->totem_config->node_id;
  819. instance->context = context;
  820. instance->totemudpu_deliver_fn = deliver_fn;
  821. instance->totemudpu_iface_change_fn = iface_change_fn;
  822. instance->totemudpu_target_set_completed = target_set_completed;
  823. /*
  824. * Create static local mcast sockets
  825. */
  826. if (totemudpu_build_local_sockets(instance) == -1) {
  827. free(instance);
  828. return (-1);
  829. }
  830. qb_loop_poll_add (
  831. instance->totemudpu_poll_handle,
  832. QB_LOOP_MED,
  833. instance->local_loop_sock[0],
  834. POLLIN, instance, net_deliver_fn);
  835. /*
  836. * RRP layer isn't ready to receive message because it hasn't
  837. * initialized yet. Add short timer to check the interfaces.
  838. */
  839. qb_loop_timer_add (instance->totemudpu_poll_handle,
  840. QB_LOOP_MED,
  841. 100*QB_TIME_NS_IN_MSEC,
  842. (void *)instance,
  843. timer_function_netif_check_timeout,
  844. &instance->timer_netif_check_timeout);
  845. totemudpu_start_merge_detect_timeout((void*)instance);
  846. *udpu_context = instance;
  847. return (0);
  848. }
  849. void *totemudpu_buffer_alloc (void)
  850. {
  851. return malloc (FRAME_SIZE_MAX);
  852. }
  853. void totemudpu_buffer_release (void *ptr)
  854. {
  855. return free (ptr);
  856. }
  857. int totemudpu_processor_count_set (
  858. void *udpu_context,
  859. int processor_count)
  860. {
  861. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  862. int res = 0;
  863. instance->my_memb_entries = processor_count;
  864. qb_loop_timer_del (instance->totemudpu_poll_handle,
  865. instance->timer_netif_check_timeout);
  866. if (processor_count == 1) {
  867. qb_loop_timer_add (instance->totemudpu_poll_handle,
  868. QB_LOOP_MED,
  869. instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
  870. (void *)instance,
  871. timer_function_netif_check_timeout,
  872. &instance->timer_netif_check_timeout);
  873. }
  874. return (res);
  875. }
  876. int totemudpu_recv_flush (void *udpu_context)
  877. {
  878. int res = 0;
  879. return (res);
  880. }
  881. int totemudpu_send_flush (void *udpu_context)
  882. {
  883. int res = 0;
  884. return (res);
  885. }
  886. int totemudpu_token_send (
  887. void *udpu_context,
  888. const void *msg,
  889. unsigned int msg_len)
  890. {
  891. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  892. int res = 0;
  893. ucast_sendmsg (instance, &instance->token_target, msg, msg_len);
  894. return (res);
  895. }
  896. int totemudpu_mcast_flush_send (
  897. void *udpu_context,
  898. const void *msg,
  899. unsigned int msg_len)
  900. {
  901. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  902. int res = 0;
  903. mcast_sendmsg (instance, msg, msg_len, 0);
  904. return (res);
  905. }
  906. int totemudpu_mcast_noflush_send (
  907. void *udpu_context,
  908. const void *msg,
  909. unsigned int msg_len)
  910. {
  911. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  912. int res = 0;
  913. mcast_sendmsg (instance, msg, msg_len, 1);
  914. return (res);
  915. }
  916. extern int totemudpu_iface_check (void *udpu_context)
  917. {
  918. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  919. int res = 0;
  920. timer_function_netif_check_timeout (instance);
  921. return (res);
  922. }
  923. extern void totemudpu_net_mtu_adjust (void *udpu_context, struct totem_config *totem_config)
  924. {
  925. totem_config->net_mtu -= totemip_udpip_header_size(totem_config->interfaces[0].bindnet.family);
  926. }
  927. int totemudpu_token_target_set (
  928. void *udpu_context,
  929. unsigned int nodeid)
  930. {
  931. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  932. struct qb_list_head *list;
  933. struct totemudpu_member *member;
  934. int res = 0;
  935. qb_list_for_each(list, &(instance->member_list)) {
  936. member = qb_list_entry (list,
  937. struct totemudpu_member,
  938. list);
  939. if (member->member.nodeid == nodeid) {
  940. memcpy (&instance->token_target, &member->member,
  941. sizeof (struct totem_ip_address));
  942. instance->totemudpu_target_set_completed (instance->context);
  943. break;
  944. }
  945. }
  946. return (res);
  947. }
  948. extern int totemudpu_recv_mcast_empty (
  949. void *udpu_context)
  950. {
  951. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  952. unsigned int res;
  953. struct sockaddr_storage system_from;
  954. struct msghdr msg_recv;
  955. struct pollfd ufd;
  956. int nfds, i;
  957. int msg_processed = 0;
  958. int sock;
  959. /*
  960. * Receive datagram
  961. */
  962. msg_recv.msg_name = &system_from;
  963. msg_recv.msg_namelen = sizeof (struct sockaddr_storage);
  964. msg_recv.msg_iov = &instance->totemudpu_iov_recv;
  965. msg_recv.msg_iovlen = 1;
  966. #ifdef HAVE_MSGHDR_CONTROL
  967. msg_recv.msg_control = 0;
  968. #endif
  969. #ifdef HAVE_MSGHDR_CONTROLLEN
  970. msg_recv.msg_controllen = 0;
  971. #endif
  972. #ifdef HAVE_MSGHDR_FLAGS
  973. msg_recv.msg_flags = 0;
  974. #endif
  975. #ifdef HAVE_MSGHDR_ACCRIGHTS
  976. msg_recv.msg_accrights = NULL;
  977. #endif
  978. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  979. msg_recv.msg_accrightslen = 0;
  980. #endif
  981. for (i = 0; i < 2; i++) {
  982. sock = -1;
  983. if (i == 0) {
  984. if (instance->netif_bind_state == BIND_STATE_REGULAR) {
  985. sock = instance->token_socket;
  986. } else {
  987. continue;
  988. }
  989. }
  990. if (i == 1) {
  991. sock = instance->local_loop_sock[0];
  992. }
  993. assert(sock != -1);
  994. do {
  995. ufd.fd = sock;
  996. ufd.events = POLLIN;
  997. nfds = poll (&ufd, 1, 0);
  998. if (nfds == 1 && ufd.revents & POLLIN) {
  999. res = recvmsg (sock, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT);
  1000. if (res != -1) {
  1001. msg_processed = 1;
  1002. } else {
  1003. msg_processed = -1;
  1004. }
  1005. }
  1006. } while (nfds == 1);
  1007. }
  1008. return (msg_processed);
  1009. }
  1010. static int totemudpu_create_sending_socket(
  1011. void *udpu_context,
  1012. const struct totem_ip_address *member)
  1013. {
  1014. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  1015. int fd;
  1016. int res;
  1017. unsigned int sendbuf_size;
  1018. unsigned int optlen = sizeof (sendbuf_size);
  1019. struct sockaddr_storage sockaddr;
  1020. int addrlen;
  1021. fd = socket (member->family, SOCK_DGRAM, 0);
  1022. if (fd == -1) {
  1023. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  1024. "Could not create socket for new member");
  1025. return (-1);
  1026. }
  1027. totemip_nosigpipe (fd);
  1028. res = fcntl (fd, F_SETFL, O_NONBLOCK);
  1029. if (res == -1) {
  1030. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  1031. "Could not set non-blocking operation on token socket");
  1032. goto error_close_fd;
  1033. }
  1034. /*
  1035. * These sockets are used to send multicast messages, so their buffers
  1036. * should be large
  1037. */
  1038. sendbuf_size = MCAST_SOCKET_BUFFER_SIZE;
  1039. res = setsockopt (fd, SOL_SOCKET, SO_SNDBUF,
  1040. &sendbuf_size, optlen);
  1041. if (res == -1) {
  1042. LOGSYS_PERROR (errno, instance->totemudpu_log_level_notice,
  1043. "Could not set sendbuf size");
  1044. /*
  1045. * Fail in setting sendbuf size is not fatal -> don't exit
  1046. */
  1047. }
  1048. /*
  1049. * Bind to sending interface
  1050. */
  1051. totemip_totemip_to_sockaddr_convert(&instance->my_id, 0, &sockaddr, &addrlen);
  1052. res = bind (fd, (struct sockaddr *)&sockaddr, addrlen);
  1053. if (res == -1) {
  1054. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  1055. "bind token socket failed");
  1056. goto error_close_fd;
  1057. }
  1058. return (fd);
  1059. error_close_fd:
  1060. close(fd);
  1061. return (-1);
  1062. }
  1063. int totemudpu_iface_set (void *net_context,
  1064. const struct totem_ip_address *local_addr,
  1065. unsigned short ip_port,
  1066. unsigned int iface_no)
  1067. {
  1068. /* Not supported */
  1069. return (-1);
  1070. }
  1071. int totemudpu_member_add (
  1072. void *udpu_context,
  1073. const struct totem_ip_address *local,
  1074. const struct totem_ip_address *member,
  1075. int ring_no)
  1076. {
  1077. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  1078. struct totemudpu_member *new_member;
  1079. new_member = malloc (sizeof (struct totemudpu_member));
  1080. if (new_member == NULL) {
  1081. return (-1);
  1082. }
  1083. memset(new_member, 0, sizeof(*new_member));
  1084. log_printf (LOGSYS_LEVEL_NOTICE, "adding new UDPU member {%s}",
  1085. totemip_print(member));
  1086. qb_list_init (&new_member->list);
  1087. qb_list_add_tail (&new_member->list, &instance->member_list);
  1088. memcpy (&new_member->member, member, sizeof (struct totem_ip_address));
  1089. new_member->fd = totemudpu_create_sending_socket(udpu_context, member);
  1090. new_member->active = 1;
  1091. return (0);
  1092. }
  1093. int totemudpu_member_remove (
  1094. void *udpu_context,
  1095. const struct totem_ip_address *token_target,
  1096. int ring_no)
  1097. {
  1098. int found = 0;
  1099. struct qb_list_head *list;
  1100. struct totemudpu_member *member;
  1101. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  1102. /*
  1103. * Find the member to remove and close its socket
  1104. */
  1105. qb_list_for_each(list, &(instance->member_list)) {
  1106. member = qb_list_entry (list,
  1107. struct totemudpu_member,
  1108. list);
  1109. if (totemip_compare (token_target, &member->member)==0) {
  1110. log_printf(LOGSYS_LEVEL_NOTICE,
  1111. "removing UDPU member {%s}",
  1112. totemip_print(&member->member));
  1113. if (member->fd > 0) {
  1114. log_printf(LOGSYS_LEVEL_DEBUG,
  1115. "Closing socket to: {%s}",
  1116. totemip_print(&member->member));
  1117. qb_loop_poll_del (instance->totemudpu_poll_handle,
  1118. member->fd);
  1119. close (member->fd);
  1120. }
  1121. found = 1;
  1122. break;
  1123. }
  1124. }
  1125. /*
  1126. * Delete the member from the list
  1127. */
  1128. if (found) {
  1129. qb_list_del (list);
  1130. }
  1131. instance = NULL;
  1132. return (0);
  1133. }
  1134. int totemudpu_member_list_rebind_ip (
  1135. void *udpu_context)
  1136. {
  1137. struct qb_list_head *list;
  1138. struct totemudpu_member *member;
  1139. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  1140. qb_list_for_each(list, &(instance->member_list)) {
  1141. member = qb_list_entry (list,
  1142. struct totemudpu_member,
  1143. list);
  1144. if (member->fd > 0) {
  1145. close (member->fd);
  1146. }
  1147. member->fd = totemudpu_create_sending_socket(udpu_context, &member->member);
  1148. }
  1149. return (0);
  1150. }
  1151. static void timer_function_merge_detect_timeout (
  1152. void *data)
  1153. {
  1154. struct totemudpu_instance *instance = (struct totemudpu_instance *)data;
  1155. if (instance->merge_detect_messages_sent_before_timeout == 0) {
  1156. instance->send_merge_detect_message = 1;
  1157. }
  1158. instance->merge_detect_messages_sent_before_timeout = 0;
  1159. totemudpu_start_merge_detect_timeout(instance);
  1160. }
  1161. static void totemudpu_start_merge_detect_timeout(
  1162. void *udpu_context)
  1163. {
  1164. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  1165. qb_loop_timer_add(instance->totemudpu_poll_handle,
  1166. QB_LOOP_MED,
  1167. instance->totem_config->merge_timeout * 2 * QB_TIME_NS_IN_MSEC,
  1168. (void *)instance,
  1169. timer_function_merge_detect_timeout,
  1170. &instance->timer_merge_detect_timeout);
  1171. }
  1172. static void totemudpu_stop_merge_detect_timeout(
  1173. void *udpu_context)
  1174. {
  1175. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  1176. qb_loop_timer_del(instance->totemudpu_poll_handle,
  1177. instance->timer_merge_detect_timeout);
  1178. }
  1179. int totemudpu_reconfigure (
  1180. void *udpu_context,
  1181. struct totem_config *totem_config)
  1182. {
  1183. /* Not supported */
  1184. return (-1);
  1185. }