totemudpu.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  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 int net_deliver_fn (
  366. int fd,
  367. int revents,
  368. void *data)
  369. {
  370. struct totemudpu_instance *instance = (struct totemudpu_instance *)data;
  371. struct msghdr msg_recv;
  372. struct iovec *iovec;
  373. struct sockaddr_storage system_from;
  374. int bytes_received;
  375. int truncated_packet;
  376. iovec = &instance->totemudpu_iov_recv;
  377. /*
  378. * Receive datagram
  379. */
  380. msg_recv.msg_name = &system_from;
  381. msg_recv.msg_namelen = sizeof (struct sockaddr_storage);
  382. msg_recv.msg_iov = iovec;
  383. msg_recv.msg_iovlen = 1;
  384. #ifdef HAVE_MSGHDR_CONTROL
  385. msg_recv.msg_control = 0;
  386. #endif
  387. #ifdef HAVE_MSGHDR_CONTROLLEN
  388. msg_recv.msg_controllen = 0;
  389. #endif
  390. #ifdef HAVE_MSGHDR_FLAGS
  391. msg_recv.msg_flags = 0;
  392. #endif
  393. #ifdef HAVE_MSGHDR_ACCRIGHTS
  394. msg_recv.msg_accrights = NULL;
  395. #endif
  396. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  397. msg_recv.msg_accrightslen = 0;
  398. #endif
  399. bytes_received = recvmsg (fd, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT);
  400. if (bytes_received == -1) {
  401. return (0);
  402. } else {
  403. instance->stats_recv += bytes_received;
  404. }
  405. truncated_packet = 0;
  406. #ifdef HAVE_MSGHDR_FLAGS
  407. if (msg_recv.msg_flags & MSG_TRUNC) {
  408. truncated_packet = 1;
  409. }
  410. #else
  411. /*
  412. * We don't have MSGHDR_FLAGS, but we can (hopefully) safely make assumption that
  413. * if bytes_received == UDP_RECEIVE_FRAME_SIZE_MAX then packet is truncated
  414. */
  415. if (bytes_received == UDP_RECEIVE_FRAME_SIZE_MAX) {
  416. truncated_packet = 1;
  417. }
  418. #endif
  419. if (truncated_packet) {
  420. log_printf (instance->totemudpu_log_level_error,
  421. "Received too big message. This may be because something bad is happening"
  422. "on the network (attack?), or you tried join more nodes than corosync is"
  423. "compiled with (%u) or bug in the code (bad estimation of "
  424. "the UDP_RECEIVE_FRAME_SIZE_MAX). Dropping packet.", PROCESSOR_COUNT_MAX);
  425. return (0);
  426. }
  427. iovec->iov_len = bytes_received;
  428. /*
  429. * Handle incoming message
  430. */
  431. instance->totemudpu_deliver_fn (
  432. instance->context,
  433. iovec->iov_base,
  434. iovec->iov_len,
  435. &system_from);
  436. iovec->iov_len = UDP_RECEIVE_FRAME_SIZE_MAX;
  437. return (0);
  438. }
  439. static int netif_determine (
  440. struct totemudpu_instance *instance,
  441. struct totem_ip_address *bindnet,
  442. struct totem_ip_address *bound_to,
  443. int *interface_up,
  444. int *interface_num)
  445. {
  446. int res;
  447. res = totemip_iface_check (bindnet, bound_to,
  448. interface_up, interface_num,
  449. instance->totem_config->clear_node_high_bit);
  450. return (res);
  451. }
  452. /*
  453. * If the interface is up, the sockets for totem are built. If the interface is down
  454. * this function is requeued in the timer list to retry building the sockets later.
  455. */
  456. static void timer_function_netif_check_timeout (
  457. void *data)
  458. {
  459. struct totemudpu_instance *instance = (struct totemudpu_instance *)data;
  460. int interface_up;
  461. int interface_num;
  462. /*
  463. * Build sockets for every interface
  464. */
  465. netif_determine (instance,
  466. &instance->totem_interface->bindnet,
  467. &instance->totem_interface->boundto,
  468. &interface_up, &interface_num);
  469. /*
  470. * If the network interface isn't back up and we are already
  471. * in loopback mode, add timer to check again and return
  472. */
  473. if ((instance->netif_bind_state == BIND_STATE_LOOPBACK &&
  474. interface_up == 0) ||
  475. (instance->my_memb_entries == 1 &&
  476. instance->netif_bind_state == BIND_STATE_REGULAR &&
  477. interface_up == 1)) {
  478. qb_loop_timer_add (instance->totemudpu_poll_handle,
  479. QB_LOOP_MED,
  480. instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
  481. (void *)instance,
  482. timer_function_netif_check_timeout,
  483. &instance->timer_netif_check_timeout);
  484. /*
  485. * Add a timer to check for a downed regular interface
  486. */
  487. return;
  488. }
  489. if (instance->token_socket > 0) {
  490. qb_loop_poll_del (instance->totemudpu_poll_handle,
  491. instance->token_socket);
  492. close (instance->token_socket);
  493. instance->token_socket = -1;
  494. }
  495. if (interface_up == 0) {
  496. if (instance->netif_bind_state == BIND_STATE_UNBOUND) {
  497. log_printf (instance->totemudpu_log_level_error,
  498. "One of your ip addresses are now bound to localhost. "
  499. "Corosync would not work correctly.");
  500. exit(COROSYNC_DONE_FATAL_ERR);
  501. }
  502. /*
  503. * Interface is not up
  504. */
  505. instance->netif_bind_state = BIND_STATE_LOOPBACK;
  506. /*
  507. * Add a timer to retry building interfaces and request memb_gather_enter
  508. */
  509. qb_loop_timer_add (instance->totemudpu_poll_handle,
  510. QB_LOOP_MED,
  511. instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
  512. (void *)instance,
  513. timer_function_netif_check_timeout,
  514. &instance->timer_netif_check_timeout);
  515. } else {
  516. /*
  517. * Interface is up
  518. */
  519. instance->netif_bind_state = BIND_STATE_REGULAR;
  520. }
  521. /*
  522. * Create and bind the multicast and unicast sockets
  523. */
  524. totemudpu_build_sockets (instance,
  525. &instance->totem_interface->bindnet,
  526. &instance->totem_interface->boundto);
  527. if (instance->netif_bind_state == BIND_STATE_REGULAR) {
  528. qb_loop_poll_add (instance->totemudpu_poll_handle,
  529. QB_LOOP_MED,
  530. instance->token_socket,
  531. POLLIN, instance, net_deliver_fn);
  532. }
  533. totemip_copy (&instance->my_id, &instance->totem_interface->boundto);
  534. /*
  535. * This reports changes in the interface to the user and totemsrp
  536. */
  537. if (instance->netif_bind_state == BIND_STATE_REGULAR) {
  538. if (instance->netif_state_report & NETIF_STATE_REPORT_UP) {
  539. log_printf (instance->totemudpu_log_level_notice,
  540. "The network interface [%s] is now up.",
  541. totemip_print (&instance->totem_interface->boundto));
  542. instance->netif_state_report = NETIF_STATE_REPORT_DOWN;
  543. instance->totemudpu_iface_change_fn (instance->context, &instance->my_id, 0);
  544. }
  545. /*
  546. * Add a timer to check for interface going down in single membership
  547. */
  548. if (instance->my_memb_entries == 1) {
  549. qb_loop_timer_add (instance->totemudpu_poll_handle,
  550. QB_LOOP_MED,
  551. instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
  552. (void *)instance,
  553. timer_function_netif_check_timeout,
  554. &instance->timer_netif_check_timeout);
  555. }
  556. } else {
  557. if (instance->netif_state_report & NETIF_STATE_REPORT_DOWN) {
  558. log_printf (instance->totemudpu_log_level_notice,
  559. "The network interface is down.");
  560. instance->totemudpu_iface_change_fn (instance->context, &instance->my_id, 0);
  561. }
  562. instance->netif_state_report = NETIF_STATE_REPORT_UP;
  563. }
  564. }
  565. /* Set the socket priority to INTERACTIVE to ensure
  566. that our messages don't get queued behind anything else */
  567. static void totemudpu_traffic_control_set(struct totemudpu_instance *instance, int sock)
  568. {
  569. #ifdef SO_PRIORITY
  570. int prio = 6; /* TC_PRIO_INTERACTIVE */
  571. if (setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(int))) {
  572. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  573. "Could not set traffic priority");
  574. }
  575. #endif
  576. }
  577. static int totemudpu_build_sockets_ip (
  578. struct totemudpu_instance *instance,
  579. struct totem_ip_address *bindnet_address,
  580. struct totem_ip_address *bound_to,
  581. int interface_num)
  582. {
  583. struct sockaddr_storage sockaddr;
  584. int addrlen;
  585. int res;
  586. unsigned int recvbuf_size;
  587. unsigned int optlen = sizeof (recvbuf_size);
  588. unsigned int retries = 0;
  589. /*
  590. * Setup unicast socket
  591. */
  592. instance->token_socket = socket (bindnet_address->family, SOCK_DGRAM, 0);
  593. if (instance->token_socket == -1) {
  594. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  595. "socket() failed");
  596. return (-1);
  597. }
  598. totemip_nosigpipe (instance->token_socket);
  599. res = fcntl (instance->token_socket, F_SETFL, O_NONBLOCK);
  600. if (res == -1) {
  601. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  602. "Could not set non-blocking operation on token socket");
  603. return (-1);
  604. }
  605. /*
  606. * Bind to unicast socket used for token send/receives
  607. * This has the side effect of binding to the correct interface
  608. */
  609. totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_interface->ip_port, &sockaddr, &addrlen);
  610. while (1) {
  611. res = bind (instance->token_socket, (struct sockaddr *)&sockaddr, addrlen);
  612. if (res == 0) {
  613. break;
  614. }
  615. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  616. "bind token socket failed");
  617. if (++retries > BIND_MAX_RETRIES) {
  618. break;
  619. }
  620. /*
  621. * Wait for a while
  622. */
  623. (void)poll(NULL, 0, BIND_RETRIES_INTERVAL * retries);
  624. }
  625. if (res == -1) {
  626. return (-1);
  627. }
  628. /*
  629. * the token_socket can receive many messages. Allow a large number
  630. * of receive messages on this socket
  631. */
  632. recvbuf_size = MCAST_SOCKET_BUFFER_SIZE;
  633. res = setsockopt (instance->token_socket, SOL_SOCKET, SO_RCVBUF,
  634. &recvbuf_size, optlen);
  635. if (res == -1) {
  636. LOGSYS_PERROR (errno, instance->totemudpu_log_level_notice,
  637. "Could not set recvbuf size");
  638. }
  639. return 0;
  640. }
  641. int totemudpu_ifaces_get (
  642. void *net_context,
  643. char ***status,
  644. unsigned int *iface_count)
  645. {
  646. static char *statuses[INTERFACE_MAX] = {(char*)"OK"};
  647. if (status) {
  648. *status = statuses;
  649. }
  650. *iface_count = 1;
  651. return (0);
  652. }
  653. static int totemudpu_build_local_sockets(
  654. struct totemudpu_instance *instance)
  655. {
  656. int i;
  657. unsigned int sendbuf_size;
  658. unsigned int recvbuf_size;
  659. unsigned int optlen = sizeof (sendbuf_size);
  660. int res;
  661. /*
  662. * Create local multicast loop socket
  663. */
  664. if (socketpair(AF_UNIX, SOCK_DGRAM, 0, instance->local_loop_sock) == -1) {
  665. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  666. "socket() failed");
  667. return (-1);
  668. }
  669. for (i = 0; i < 2; i++) {
  670. totemip_nosigpipe (instance->local_loop_sock[i]);
  671. res = fcntl (instance->local_loop_sock[i], F_SETFL, O_NONBLOCK);
  672. if (res == -1) {
  673. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  674. "Could not set non-blocking operation on multicast socket");
  675. return (-1);
  676. }
  677. }
  678. recvbuf_size = MCAST_SOCKET_BUFFER_SIZE;
  679. sendbuf_size = MCAST_SOCKET_BUFFER_SIZE;
  680. res = setsockopt (instance->local_loop_sock[0], SOL_SOCKET, SO_RCVBUF, &recvbuf_size, optlen);
  681. if (res == -1) {
  682. LOGSYS_PERROR (errno, instance->totemudpu_log_level_debug,
  683. "Unable to set SO_RCVBUF size on UDP local mcast loop socket");
  684. return (-1);
  685. }
  686. res = setsockopt (instance->local_loop_sock[1], SOL_SOCKET, SO_SNDBUF, &sendbuf_size, optlen);
  687. if (res == -1) {
  688. LOGSYS_PERROR (errno, instance->totemudpu_log_level_debug,
  689. "Unable to set SO_SNDBUF size on UDP local mcast loop socket");
  690. return (-1);
  691. }
  692. res = getsockopt (instance->local_loop_sock[0], SOL_SOCKET, SO_RCVBUF, &recvbuf_size, &optlen);
  693. if (res == 0) {
  694. log_printf (instance->totemudpu_log_level_debug,
  695. "Local receive multicast loop socket recv buffer size (%d bytes).", recvbuf_size);
  696. }
  697. res = getsockopt (instance->local_loop_sock[1], SOL_SOCKET, SO_SNDBUF, &sendbuf_size, &optlen);
  698. if (res == 0) {
  699. log_printf (instance->totemudpu_log_level_debug,
  700. "Local transmit multicast loop socket send buffer size (%d bytes).", sendbuf_size);
  701. }
  702. return (0);
  703. }
  704. static int totemudpu_build_sockets (
  705. struct totemudpu_instance *instance,
  706. struct totem_ip_address *bindnet_address,
  707. struct totem_ip_address *bound_to)
  708. {
  709. int interface_num;
  710. int interface_up;
  711. int res;
  712. /*
  713. * Determine the ip address bound to and the interface name
  714. */
  715. res = netif_determine (instance,
  716. bindnet_address,
  717. bound_to,
  718. &interface_up,
  719. &interface_num);
  720. if (res == -1) {
  721. return (-1);
  722. }
  723. totemip_copy(&instance->my_id, bound_to);
  724. res = totemudpu_build_sockets_ip (instance,
  725. bindnet_address, bound_to, interface_num);
  726. if (res == -1) {
  727. /* if we get here, corosync won't work anyway, so better leaving than faking to work */
  728. LOGSYS_PERROR (errno, instance->totemudpu_log_level_error,
  729. "Unable to create sockets, exiting");
  730. exit(EXIT_FAILURE);
  731. }
  732. /* We only send out of the token socket */
  733. totemudpu_traffic_control_set(instance, instance->token_socket);
  734. /*
  735. * Rebind all members to new ips
  736. */
  737. totemudpu_member_list_rebind_ip(instance);
  738. return res;
  739. }
  740. /*
  741. * Totem Network interface
  742. * depends on poll abstraction, POSIX, IPV4
  743. */
  744. /*
  745. * Create an instance
  746. */
  747. int totemudpu_initialize (
  748. qb_loop_t *poll_handle,
  749. void **udpu_context,
  750. struct totem_config *totem_config,
  751. totemsrp_stats_t *stats,
  752. void *context,
  753. void (*deliver_fn) (
  754. void *context,
  755. const void *msg,
  756. unsigned int msg_len,
  757. const struct sockaddr_storage *system_from),
  758. void (*iface_change_fn) (
  759. void *context,
  760. const struct totem_ip_address *iface_address,
  761. unsigned int ring_no),
  762. void (*mtu_changed) (
  763. void *context,
  764. int net_mtu),
  765. void (*target_set_completed) (
  766. void *context))
  767. {
  768. struct totemudpu_instance *instance;
  769. instance = malloc (sizeof (struct totemudpu_instance));
  770. if (instance == NULL) {
  771. return (-1);
  772. }
  773. totemudpu_instance_initialize (instance);
  774. instance->totem_config = totem_config;
  775. instance->stats = stats;
  776. /*
  777. * Configure logging
  778. */
  779. instance->totemudpu_log_level_security = 1; //totem_config->totem_logging_configuration.log_level_security;
  780. instance->totemudpu_log_level_error = totem_config->totem_logging_configuration.log_level_error;
  781. instance->totemudpu_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
  782. instance->totemudpu_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
  783. instance->totemudpu_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
  784. instance->totemudpu_subsys_id = totem_config->totem_logging_configuration.log_subsys_id;
  785. instance->totemudpu_log_printf = totem_config->totem_logging_configuration.log_printf;
  786. /*
  787. * Initialize local variables for totemudpu
  788. */
  789. instance->totem_interface = &totem_config->interfaces[0];
  790. memset (instance->iov_buffer, 0, UDP_RECEIVE_FRAME_SIZE_MAX);
  791. instance->totemudpu_poll_handle = poll_handle;
  792. instance->totem_interface->bindnet.nodeid = instance->totem_config->node_id;
  793. instance->context = context;
  794. instance->totemudpu_deliver_fn = deliver_fn;
  795. instance->totemudpu_iface_change_fn = iface_change_fn;
  796. instance->totemudpu_target_set_completed = target_set_completed;
  797. /*
  798. * Create static local mcast sockets
  799. */
  800. if (totemudpu_build_local_sockets(instance) == -1) {
  801. free(instance);
  802. return (-1);
  803. }
  804. qb_loop_poll_add (
  805. instance->totemudpu_poll_handle,
  806. QB_LOOP_MED,
  807. instance->local_loop_sock[0],
  808. POLLIN, instance, net_deliver_fn);
  809. /*
  810. * RRP layer isn't ready to receive message because it hasn't
  811. * initialized yet. Add short timer to check the interfaces.
  812. */
  813. qb_loop_timer_add (instance->totemudpu_poll_handle,
  814. QB_LOOP_MED,
  815. 100*QB_TIME_NS_IN_MSEC,
  816. (void *)instance,
  817. timer_function_netif_check_timeout,
  818. &instance->timer_netif_check_timeout);
  819. totemudpu_start_merge_detect_timeout((void*)instance);
  820. *udpu_context = instance;
  821. return (0);
  822. }
  823. void *totemudpu_buffer_alloc (void)
  824. {
  825. return malloc (FRAME_SIZE_MAX);
  826. }
  827. void totemudpu_buffer_release (void *ptr)
  828. {
  829. return free (ptr);
  830. }
  831. int totemudpu_processor_count_set (
  832. void *udpu_context,
  833. int processor_count)
  834. {
  835. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  836. int res = 0;
  837. instance->my_memb_entries = processor_count;
  838. qb_loop_timer_del (instance->totemudpu_poll_handle,
  839. instance->timer_netif_check_timeout);
  840. if (processor_count == 1) {
  841. qb_loop_timer_add (instance->totemudpu_poll_handle,
  842. QB_LOOP_MED,
  843. instance->totem_config->downcheck_timeout*QB_TIME_NS_IN_MSEC,
  844. (void *)instance,
  845. timer_function_netif_check_timeout,
  846. &instance->timer_netif_check_timeout);
  847. }
  848. return (res);
  849. }
  850. int totemudpu_recv_flush (void *udpu_context)
  851. {
  852. int res = 0;
  853. return (res);
  854. }
  855. int totemudpu_send_flush (void *udpu_context)
  856. {
  857. int res = 0;
  858. return (res);
  859. }
  860. int totemudpu_token_send (
  861. void *udpu_context,
  862. const void *msg,
  863. unsigned int msg_len)
  864. {
  865. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  866. int res = 0;
  867. ucast_sendmsg (instance, &instance->token_target, msg, msg_len);
  868. return (res);
  869. }
  870. int totemudpu_mcast_flush_send (
  871. void *udpu_context,
  872. const void *msg,
  873. unsigned int msg_len)
  874. {
  875. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  876. int res = 0;
  877. mcast_sendmsg (instance, msg, msg_len, 0);
  878. return (res);
  879. }
  880. int totemudpu_mcast_noflush_send (
  881. void *udpu_context,
  882. const void *msg,
  883. unsigned int msg_len)
  884. {
  885. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  886. int res = 0;
  887. mcast_sendmsg (instance, msg, msg_len, 1);
  888. return (res);
  889. }
  890. extern int totemudpu_iface_check (void *udpu_context)
  891. {
  892. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  893. int res = 0;
  894. timer_function_netif_check_timeout (instance);
  895. return (res);
  896. }
  897. extern void totemudpu_net_mtu_adjust (void *udpu_context, struct totem_config *totem_config)
  898. {
  899. totem_config->net_mtu -= totemip_udpip_header_size(totem_config->interfaces[0].bindnet.family);
  900. }
  901. int totemudpu_token_target_set (
  902. void *udpu_context,
  903. unsigned int nodeid)
  904. {
  905. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  906. struct qb_list_head *list;
  907. struct totemudpu_member *member;
  908. int res = 0;
  909. qb_list_for_each(list, &(instance->member_list)) {
  910. member = qb_list_entry (list,
  911. struct totemudpu_member,
  912. list);
  913. if (member->member.nodeid == nodeid) {
  914. memcpy (&instance->token_target, &member->member,
  915. sizeof (struct totem_ip_address));
  916. instance->totemudpu_target_set_completed (instance->context);
  917. break;
  918. }
  919. }
  920. return (res);
  921. }
  922. extern int totemudpu_recv_mcast_empty (
  923. void *udpu_context)
  924. {
  925. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  926. unsigned int res;
  927. struct sockaddr_storage system_from;
  928. struct msghdr msg_recv;
  929. struct pollfd ufd;
  930. int nfds, i;
  931. int msg_processed = 0;
  932. int sock;
  933. /*
  934. * Receive datagram
  935. */
  936. msg_recv.msg_name = &system_from;
  937. msg_recv.msg_namelen = sizeof (struct sockaddr_storage);
  938. msg_recv.msg_iov = &instance->totemudpu_iov_recv;
  939. msg_recv.msg_iovlen = 1;
  940. #ifdef HAVE_MSGHDR_CONTROL
  941. msg_recv.msg_control = 0;
  942. #endif
  943. #ifdef HAVE_MSGHDR_CONTROLLEN
  944. msg_recv.msg_controllen = 0;
  945. #endif
  946. #ifdef HAVE_MSGHDR_FLAGS
  947. msg_recv.msg_flags = 0;
  948. #endif
  949. #ifdef HAVE_MSGHDR_ACCRIGHTS
  950. msg_recv.msg_accrights = NULL;
  951. #endif
  952. #ifdef HAVE_MSGHDR_ACCRIGHTSLEN
  953. msg_recv.msg_accrightslen = 0;
  954. #endif
  955. for (i = 0; i < 2; i++) {
  956. sock = -1;
  957. if (i == 0) {
  958. if (instance->netif_bind_state == BIND_STATE_REGULAR) {
  959. sock = instance->token_socket;
  960. } else {
  961. continue;
  962. }
  963. }
  964. if (i == 1) {
  965. sock = instance->local_loop_sock[0];
  966. }
  967. assert(sock != -1);
  968. do {
  969. ufd.fd = sock;
  970. ufd.events = POLLIN;
  971. nfds = poll (&ufd, 1, 0);
  972. if (nfds == 1 && ufd.revents & POLLIN) {
  973. res = recvmsg (sock, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT);
  974. if (res != -1) {
  975. msg_processed = 1;
  976. } else {
  977. msg_processed = -1;
  978. }
  979. }
  980. } while (nfds == 1);
  981. }
  982. return (msg_processed);
  983. }
  984. static int totemudpu_create_sending_socket(
  985. void *udpu_context,
  986. const struct totem_ip_address *member)
  987. {
  988. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  989. int fd;
  990. int res;
  991. unsigned int sendbuf_size;
  992. unsigned int optlen = sizeof (sendbuf_size);
  993. struct sockaddr_storage sockaddr;
  994. int addrlen;
  995. fd = socket (member->family, SOCK_DGRAM, 0);
  996. if (fd == -1) {
  997. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  998. "Could not create socket for new member");
  999. return (-1);
  1000. }
  1001. totemip_nosigpipe (fd);
  1002. res = fcntl (fd, F_SETFL, O_NONBLOCK);
  1003. if (res == -1) {
  1004. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  1005. "Could not set non-blocking operation on token socket");
  1006. goto error_close_fd;
  1007. }
  1008. /*
  1009. * These sockets are used to send multicast messages, so their buffers
  1010. * should be large
  1011. */
  1012. sendbuf_size = MCAST_SOCKET_BUFFER_SIZE;
  1013. res = setsockopt (fd, SOL_SOCKET, SO_SNDBUF,
  1014. &sendbuf_size, optlen);
  1015. if (res == -1) {
  1016. LOGSYS_PERROR (errno, instance->totemudpu_log_level_notice,
  1017. "Could not set sendbuf size");
  1018. /*
  1019. * Fail in setting sendbuf size is not fatal -> don't exit
  1020. */
  1021. }
  1022. /*
  1023. * Bind to sending interface
  1024. */
  1025. totemip_totemip_to_sockaddr_convert(&instance->my_id, 0, &sockaddr, &addrlen);
  1026. res = bind (fd, (struct sockaddr *)&sockaddr, addrlen);
  1027. if (res == -1) {
  1028. LOGSYS_PERROR (errno, instance->totemudpu_log_level_warning,
  1029. "bind token socket failed");
  1030. goto error_close_fd;
  1031. }
  1032. return (fd);
  1033. error_close_fd:
  1034. close(fd);
  1035. return (-1);
  1036. }
  1037. int totemudpu_iface_set (void *net_context,
  1038. const struct totem_ip_address *local_addr,
  1039. unsigned short ip_port,
  1040. unsigned int iface_no)
  1041. {
  1042. /* Not supported */
  1043. return (-1);
  1044. }
  1045. int totemudpu_member_add (
  1046. void *udpu_context,
  1047. const struct totem_ip_address *local,
  1048. const struct totem_ip_address *member,
  1049. int ring_no)
  1050. {
  1051. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  1052. struct totemudpu_member *new_member;
  1053. new_member = malloc (sizeof (struct totemudpu_member));
  1054. if (new_member == NULL) {
  1055. return (-1);
  1056. }
  1057. memset(new_member, 0, sizeof(*new_member));
  1058. log_printf (LOGSYS_LEVEL_NOTICE, "adding new UDPU member {%s}",
  1059. totemip_print(member));
  1060. qb_list_init (&new_member->list);
  1061. qb_list_add_tail (&new_member->list, &instance->member_list);
  1062. memcpy (&new_member->member, member, sizeof (struct totem_ip_address));
  1063. new_member->fd = totemudpu_create_sending_socket(udpu_context, member);
  1064. new_member->active = 1;
  1065. return (0);
  1066. }
  1067. int totemudpu_member_remove (
  1068. void *udpu_context,
  1069. const struct totem_ip_address *token_target,
  1070. int ring_no)
  1071. {
  1072. int found = 0;
  1073. struct qb_list_head *list;
  1074. struct totemudpu_member *member;
  1075. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  1076. /*
  1077. * Find the member to remove and close its socket
  1078. */
  1079. qb_list_for_each(list, &(instance->member_list)) {
  1080. member = qb_list_entry (list,
  1081. struct totemudpu_member,
  1082. list);
  1083. if (totemip_compare (token_target, &member->member)==0) {
  1084. log_printf(LOGSYS_LEVEL_NOTICE,
  1085. "removing UDPU member {%s}",
  1086. totemip_print(&member->member));
  1087. if (member->fd > 0) {
  1088. log_printf(LOGSYS_LEVEL_DEBUG,
  1089. "Closing socket to: {%s}",
  1090. totemip_print(&member->member));
  1091. qb_loop_poll_del (instance->totemudpu_poll_handle,
  1092. member->fd);
  1093. close (member->fd);
  1094. }
  1095. found = 1;
  1096. break;
  1097. }
  1098. }
  1099. /*
  1100. * Delete the member from the list
  1101. */
  1102. if (found) {
  1103. qb_list_del (list);
  1104. }
  1105. instance = NULL;
  1106. return (0);
  1107. }
  1108. int totemudpu_member_list_rebind_ip (
  1109. void *udpu_context)
  1110. {
  1111. struct qb_list_head *list;
  1112. struct totemudpu_member *member;
  1113. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  1114. qb_list_for_each(list, &(instance->member_list)) {
  1115. member = qb_list_entry (list,
  1116. struct totemudpu_member,
  1117. list);
  1118. if (member->fd > 0) {
  1119. close (member->fd);
  1120. }
  1121. member->fd = totemudpu_create_sending_socket(udpu_context, &member->member);
  1122. }
  1123. return (0);
  1124. }
  1125. static void timer_function_merge_detect_timeout (
  1126. void *data)
  1127. {
  1128. struct totemudpu_instance *instance = (struct totemudpu_instance *)data;
  1129. if (instance->merge_detect_messages_sent_before_timeout == 0) {
  1130. instance->send_merge_detect_message = 1;
  1131. }
  1132. instance->merge_detect_messages_sent_before_timeout = 0;
  1133. totemudpu_start_merge_detect_timeout(instance);
  1134. }
  1135. static void totemudpu_start_merge_detect_timeout(
  1136. void *udpu_context)
  1137. {
  1138. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  1139. qb_loop_timer_add(instance->totemudpu_poll_handle,
  1140. QB_LOOP_MED,
  1141. instance->totem_config->merge_timeout * 2 * QB_TIME_NS_IN_MSEC,
  1142. (void *)instance,
  1143. timer_function_merge_detect_timeout,
  1144. &instance->timer_merge_detect_timeout);
  1145. }
  1146. static void totemudpu_stop_merge_detect_timeout(
  1147. void *udpu_context)
  1148. {
  1149. struct totemudpu_instance *instance = (struct totemudpu_instance *)udpu_context;
  1150. qb_loop_timer_del(instance->totemudpu_poll_handle,
  1151. instance->timer_merge_detect_timeout);
  1152. }
  1153. int totemudpu_reconfigure (
  1154. void *udpu_context,
  1155. struct totem_config *totem_config)
  1156. {
  1157. /* Not supported */
  1158. return (-1);
  1159. }