totemudpu.c 35 KB

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