msg.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /*
  2. * Copyright (c) 2015 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Jan Friesse (jfriesse@redhat.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the Red Hat, 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 <sys/types.h>
  35. #include <arpa/inet.h>
  36. #include <inttypes.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39. #include "msg.h"
  40. #define MSG_TYPE_LENGTH 2
  41. #define MSG_LENGTH_LENGTH 4
  42. #define MSG_STATIC_SUPPORTED_MESSAGES_SIZE 10
  43. enum msg_type msg_static_supported_messages[MSG_STATIC_SUPPORTED_MESSAGES_SIZE] = {
  44. MSG_TYPE_PREINIT,
  45. MSG_TYPE_PREINIT_REPLY,
  46. MSG_TYPE_STARTTLS,
  47. MSG_TYPE_INIT,
  48. MSG_TYPE_INIT_REPLY,
  49. MSG_TYPE_SERVER_ERROR,
  50. MSG_TYPE_SET_OPTION,
  51. MSG_TYPE_SET_OPTION_REPLY,
  52. MSG_TYPE_ECHO_REQUEST,
  53. MSG_TYPE_ECHO_REPLY,
  54. };
  55. size_t
  56. msg_get_header_length(void)
  57. {
  58. return (MSG_TYPE_LENGTH + MSG_LENGTH_LENGTH);
  59. }
  60. static void
  61. msg_add_type(struct dynar *msg, enum msg_type type)
  62. {
  63. uint16_t ntype;
  64. ntype = htons((uint16_t)type);
  65. dynar_cat(msg, &ntype, sizeof(ntype));
  66. }
  67. enum msg_type
  68. msg_get_type(const struct dynar *msg)
  69. {
  70. uint16_t ntype;
  71. uint16_t type;
  72. memcpy(&ntype, dynar_data(msg), sizeof(ntype));
  73. type = ntohs(ntype);
  74. return (type);
  75. }
  76. /*
  77. * We don't know size of message before call of this function, so zero is
  78. * added. Real value is set afterwards by msg_set_len.
  79. */
  80. static void
  81. msg_add_len(struct dynar *msg)
  82. {
  83. uint32_t len;
  84. len = 0;
  85. dynar_cat(msg, &len, sizeof(len));
  86. }
  87. static void
  88. msg_set_len(struct dynar *msg, uint32_t len)
  89. {
  90. uint32_t nlen;
  91. nlen = htonl(len);
  92. memcpy(dynar_data(msg) + MSG_TYPE_LENGTH, &nlen, sizeof(nlen));
  93. }
  94. /*
  95. * Used only for echo reply msg. All other messages should use msg_add_type.
  96. */
  97. static void
  98. msg_set_type(struct dynar *msg, enum msg_type type)
  99. {
  100. uint16_t ntype;
  101. ntype = htons((uint16_t)type);
  102. memcpy(dynar_data(msg), &ntype, sizeof(ntype));
  103. }
  104. uint32_t
  105. msg_get_len(const struct dynar *msg)
  106. {
  107. uint32_t nlen;
  108. uint32_t len;
  109. memcpy(&nlen, dynar_data(msg) + MSG_TYPE_LENGTH, sizeof(nlen));
  110. len = ntohl(nlen);
  111. return (len);
  112. }
  113. size_t
  114. msg_create_preinit(struct dynar *msg, const char *cluster_name, int add_msg_seq_number, uint32_t msg_seq_number)
  115. {
  116. dynar_clean(msg);
  117. msg_add_type(msg, MSG_TYPE_PREINIT);
  118. msg_add_len(msg);
  119. if (add_msg_seq_number) {
  120. if (tlv_add_msg_seq_number(msg, msg_seq_number) == -1) {
  121. goto small_buf_err;
  122. }
  123. }
  124. if (tlv_add_cluster_name(msg, cluster_name) == -1) {
  125. goto small_buf_err;
  126. }
  127. msg_set_len(msg, dynar_size(msg) - (MSG_TYPE_LENGTH + MSG_LENGTH_LENGTH));
  128. return (dynar_size(msg));
  129. small_buf_err:
  130. return (0);
  131. }
  132. size_t
  133. msg_create_preinit_reply(struct dynar *msg, int add_msg_seq_number, uint32_t msg_seq_number,
  134. enum tlv_tls_supported tls_supported, int tls_client_cert_required)
  135. {
  136. dynar_clean(msg);
  137. msg_add_type(msg, MSG_TYPE_PREINIT_REPLY);
  138. msg_add_len(msg);
  139. if (add_msg_seq_number) {
  140. if (tlv_add_msg_seq_number(msg, msg_seq_number) == -1) {
  141. goto small_buf_err;
  142. }
  143. }
  144. if (tlv_add_tls_supported(msg, tls_supported) == -1) {
  145. goto small_buf_err;
  146. }
  147. if (tlv_add_tls_client_cert_required(msg, tls_client_cert_required) == -1) {
  148. goto small_buf_err;
  149. }
  150. msg_set_len(msg, dynar_size(msg) - (MSG_TYPE_LENGTH + MSG_LENGTH_LENGTH));
  151. return (dynar_size(msg));
  152. small_buf_err:
  153. return (0);
  154. }
  155. size_t
  156. msg_create_starttls(struct dynar *msg, int add_msg_seq_number, uint32_t msg_seq_number)
  157. {
  158. dynar_clean(msg);
  159. msg_add_type(msg, MSG_TYPE_STARTTLS);
  160. msg_add_len(msg);
  161. if (add_msg_seq_number) {
  162. if (tlv_add_msg_seq_number(msg, msg_seq_number) == -1) {
  163. goto small_buf_err;
  164. }
  165. }
  166. msg_set_len(msg, dynar_size(msg) - (MSG_TYPE_LENGTH + MSG_LENGTH_LENGTH));
  167. return (dynar_size(msg));
  168. small_buf_err:
  169. return (0);
  170. }
  171. size_t
  172. msg_create_server_error(struct dynar *msg, int add_msg_seq_number, uint32_t msg_seq_number,
  173. enum tlv_reply_error_code reply_error_code)
  174. {
  175. dynar_clean(msg);
  176. msg_add_type(msg, MSG_TYPE_SERVER_ERROR);
  177. msg_add_len(msg);
  178. if (add_msg_seq_number) {
  179. if (tlv_add_msg_seq_number(msg, msg_seq_number) == -1) {
  180. goto small_buf_err;
  181. }
  182. }
  183. if (tlv_add_reply_error_code(msg, reply_error_code) == -1) {
  184. goto small_buf_err;
  185. }
  186. msg_set_len(msg, dynar_size(msg) - (MSG_TYPE_LENGTH + MSG_LENGTH_LENGTH));
  187. return (dynar_size(msg));
  188. small_buf_err:
  189. return (0);
  190. }
  191. static uint16_t *
  192. msg_convert_msg_type_array_to_u16_array(const enum msg_type *msg_type_array, size_t array_size)
  193. {
  194. uint16_t *u16a;
  195. size_t i;
  196. u16a = malloc(sizeof(*u16a) * array_size);
  197. if (u16a == NULL) {
  198. return (NULL);
  199. }
  200. for (i = 0; i < array_size; i++) {
  201. u16a[i] = (uint16_t)msg_type_array[i];
  202. }
  203. return (u16a);
  204. }
  205. size_t
  206. msg_create_init(struct dynar *msg, int add_msg_seq_number, uint32_t msg_seq_number,
  207. const enum msg_type *supported_msgs, size_t no_supported_msgs,
  208. const enum tlv_opt_type *supported_opts, size_t no_supported_opts, uint32_t node_id)
  209. {
  210. uint16_t *u16a;
  211. int res;
  212. u16a = NULL;
  213. dynar_clean(msg);
  214. msg_add_type(msg, MSG_TYPE_INIT);
  215. msg_add_len(msg);
  216. if (add_msg_seq_number) {
  217. if (tlv_add_msg_seq_number(msg, msg_seq_number) == -1) {
  218. goto small_buf_err;
  219. }
  220. }
  221. if (supported_msgs != NULL && no_supported_msgs > 0) {
  222. u16a = msg_convert_msg_type_array_to_u16_array(supported_msgs, no_supported_msgs);
  223. if (u16a == NULL) {
  224. goto small_buf_err;
  225. }
  226. res = tlv_add_u16_array(msg, TLV_OPT_SUPPORTED_MESSAGES, u16a, no_supported_msgs);
  227. free(u16a);
  228. if (res == -1) {
  229. goto small_buf_err;
  230. }
  231. }
  232. if (supported_opts != NULL && no_supported_opts > 0) {
  233. if (tlv_add_supported_options(msg, supported_opts, no_supported_opts) == -1) {
  234. goto small_buf_err;
  235. }
  236. }
  237. if (tlv_add_node_id(msg, node_id) == -1) {
  238. goto small_buf_err;
  239. }
  240. msg_set_len(msg, dynar_size(msg) - (MSG_TYPE_LENGTH + MSG_LENGTH_LENGTH));
  241. return (dynar_size(msg));
  242. small_buf_err:
  243. return (0);
  244. }
  245. size_t
  246. msg_create_init_reply(struct dynar *msg, int add_msg_seq_number, uint32_t msg_seq_number,
  247. const enum msg_type *supported_msgs, size_t no_supported_msgs,
  248. const enum tlv_opt_type *supported_opts, size_t no_supported_opts,
  249. size_t server_maximum_request_size, size_t server_maximum_reply_size,
  250. const enum tlv_decision_algorithm_type *supported_decision_algorithms, size_t no_supported_decision_algorithms)
  251. {
  252. uint16_t *u16a;
  253. int res;
  254. u16a = NULL;
  255. dynar_clean(msg);
  256. msg_add_type(msg, MSG_TYPE_INIT_REPLY);
  257. msg_add_len(msg);
  258. if (supported_msgs != NULL && no_supported_msgs > 0) {
  259. u16a = msg_convert_msg_type_array_to_u16_array(supported_msgs, no_supported_msgs);
  260. if (u16a == NULL) {
  261. goto small_buf_err;
  262. }
  263. res = tlv_add_u16_array(msg, TLV_OPT_SUPPORTED_MESSAGES, u16a, no_supported_msgs);
  264. free(u16a);
  265. if (res == -1) {
  266. goto small_buf_err;
  267. }
  268. }
  269. if (supported_opts != NULL && no_supported_opts > 0) {
  270. if (tlv_add_supported_options(msg, supported_opts, no_supported_opts) == -1) {
  271. goto small_buf_err;
  272. }
  273. }
  274. if (add_msg_seq_number) {
  275. if (tlv_add_msg_seq_number(msg, msg_seq_number) == -1) {
  276. goto small_buf_err;
  277. }
  278. }
  279. if (tlv_add_server_maximum_request_size(msg, server_maximum_request_size) == -1) {
  280. goto small_buf_err;
  281. }
  282. if (tlv_add_server_maximum_reply_size(msg, server_maximum_reply_size) == -1) {
  283. goto small_buf_err;
  284. }
  285. if (supported_decision_algorithms != NULL && no_supported_decision_algorithms > 0) {
  286. if (tlv_add_supported_decision_algorithms(msg, supported_decision_algorithms,
  287. no_supported_decision_algorithms) == -1) {
  288. goto small_buf_err;
  289. }
  290. }
  291. msg_set_len(msg, dynar_size(msg) - (MSG_TYPE_LENGTH + MSG_LENGTH_LENGTH));
  292. return (dynar_size(msg));
  293. small_buf_err:
  294. return (0);
  295. }
  296. size_t
  297. msg_create_set_option(struct dynar *msg, int add_msg_seq_number, uint32_t msg_seq_number,
  298. int add_decision_algorithm, enum tlv_decision_algorithm_type decision_algorithm,
  299. int add_heartbeat_interval, uint32_t heartbeat_interval)
  300. {
  301. dynar_clean(msg);
  302. msg_add_type(msg, MSG_TYPE_SET_OPTION);
  303. msg_add_len(msg);
  304. if (add_msg_seq_number) {
  305. if (tlv_add_msg_seq_number(msg, msg_seq_number) == -1) {
  306. goto small_buf_err;
  307. }
  308. }
  309. if (add_decision_algorithm) {
  310. if (tlv_add_decision_algorithm(msg, decision_algorithm) == -1) {
  311. goto small_buf_err;
  312. }
  313. }
  314. if (add_heartbeat_interval) {
  315. if (tlv_add_heartbeat_interval(msg, heartbeat_interval) == -1) {
  316. goto small_buf_err;
  317. }
  318. }
  319. msg_set_len(msg, dynar_size(msg) - (MSG_TYPE_LENGTH + MSG_LENGTH_LENGTH));
  320. return (dynar_size(msg));
  321. small_buf_err:
  322. return (0);
  323. }
  324. size_t
  325. msg_create_set_option_reply(struct dynar *msg, int add_msg_seq_number, uint32_t msg_seq_number,
  326. enum tlv_decision_algorithm_type decision_algorithm, uint32_t heartbeat_interval)
  327. {
  328. dynar_clean(msg);
  329. msg_add_type(msg, MSG_TYPE_SET_OPTION_REPLY);
  330. msg_add_len(msg);
  331. if (add_msg_seq_number) {
  332. if (tlv_add_msg_seq_number(msg, msg_seq_number) == -1) {
  333. goto small_buf_err;
  334. }
  335. }
  336. if (tlv_add_decision_algorithm(msg, decision_algorithm) == -1) {
  337. goto small_buf_err;
  338. }
  339. if (tlv_add_heartbeat_interval(msg, heartbeat_interval) == -1) {
  340. goto small_buf_err;
  341. }
  342. msg_set_len(msg, dynar_size(msg) - (MSG_TYPE_LENGTH + MSG_LENGTH_LENGTH));
  343. return (dynar_size(msg));
  344. small_buf_err:
  345. return (0);
  346. }
  347. size_t
  348. msg_create_echo_request(struct dynar *msg, int add_msg_seq_number, uint32_t msg_seq_number)
  349. {
  350. dynar_clean(msg);
  351. msg_add_type(msg, MSG_TYPE_ECHO_REQUEST);
  352. msg_add_len(msg);
  353. if (add_msg_seq_number) {
  354. if (tlv_add_msg_seq_number(msg, msg_seq_number) == -1) {
  355. goto small_buf_err;
  356. }
  357. }
  358. msg_set_len(msg, dynar_size(msg) - (MSG_TYPE_LENGTH + MSG_LENGTH_LENGTH));
  359. return (dynar_size(msg));
  360. small_buf_err:
  361. return (0);
  362. }
  363. size_t
  364. msg_create_echo_reply(struct dynar *msg, const struct dynar *echo_request_msg)
  365. {
  366. dynar_clean(msg);
  367. if (dynar_cat(msg, dynar_data(echo_request_msg), dynar_size(echo_request_msg)) == -1) {
  368. goto small_buf_err;
  369. }
  370. msg_set_type(msg, MSG_TYPE_ECHO_REPLY);
  371. return (dynar_size(msg));
  372. small_buf_err:
  373. return (0);
  374. }
  375. int
  376. msg_is_valid_msg_type(const struct dynar *msg)
  377. {
  378. enum msg_type type;
  379. size_t i;
  380. type = msg_get_type(msg);
  381. for (i = 0; i < MSG_STATIC_SUPPORTED_MESSAGES_SIZE; i++) {
  382. if (msg_static_supported_messages[i] == type) {
  383. return (1);
  384. }
  385. }
  386. return (0);
  387. }
  388. void
  389. msg_decoded_init(struct msg_decoded *decoded_msg)
  390. {
  391. memset(decoded_msg, 0, sizeof(*decoded_msg));
  392. }
  393. void
  394. msg_decoded_destroy(struct msg_decoded *decoded_msg)
  395. {
  396. free(decoded_msg->cluster_name);
  397. free(decoded_msg->supported_messages);
  398. free(decoded_msg->supported_options);
  399. msg_decoded_init(decoded_msg);
  400. }
  401. /*
  402. * 0 - No error
  403. * -1 - option with invalid length
  404. * -2 - Unable to allocate memory
  405. * -3 - Inconsistent msg (tlv len > msg size)
  406. * -4 - invalid option content
  407. */
  408. int
  409. msg_decode(const struct dynar *msg, struct msg_decoded *decoded_msg)
  410. {
  411. struct tlv_iterator tlv_iter;
  412. uint16_t *u16a;
  413. uint32_t u32;
  414. size_t zi;
  415. enum tlv_opt_type opt_type;
  416. int iter_res;
  417. int res;
  418. msg_decoded_destroy(decoded_msg);
  419. decoded_msg->type = msg_get_type(msg);
  420. tlv_iter_init(msg, msg_get_header_length(), &tlv_iter);
  421. while ((iter_res = tlv_iter_next(&tlv_iter)) > 0) {
  422. opt_type = tlv_iter_get_type(&tlv_iter);
  423. switch (opt_type) {
  424. case TLV_OPT_MSG_SEQ_NUMBER:
  425. if (tlv_iter_decode_u32(&tlv_iter, &decoded_msg->seq_number) != 0) {
  426. return (-1);
  427. }
  428. decoded_msg->seq_number_set = 1;
  429. break;
  430. case TLV_OPT_CLUSTER_NAME:
  431. if (tlv_iter_decode_str(&tlv_iter, &decoded_msg->cluster_name,
  432. &decoded_msg->cluster_name_len) != 0) {
  433. return (-2);
  434. }
  435. break;
  436. case TLV_OPT_TLS_SUPPORTED:
  437. if ((res = tlv_iter_decode_tls_supported(&tlv_iter, &decoded_msg->tls_supported)) != 0) {
  438. return (res);
  439. }
  440. decoded_msg->tls_supported_set = 1;
  441. break;
  442. case TLV_OPT_TLS_CLIENT_CERT_REQUIRED:
  443. if (tlv_iter_decode_client_cert_required(&tlv_iter, &decoded_msg->tls_client_cert_required) != 0) {
  444. return (-1);
  445. }
  446. decoded_msg->tls_client_cert_required_set = 1;
  447. break;
  448. case TLV_OPT_SUPPORTED_MESSAGES:
  449. free(decoded_msg->supported_messages);
  450. if ((res = tlv_iter_decode_u16_array(&tlv_iter, &u16a,
  451. &decoded_msg->no_supported_messages)) != 0) {
  452. return (res);
  453. }
  454. decoded_msg->supported_messages = malloc(sizeof(enum msg_type) * decoded_msg->no_supported_messages);
  455. if (decoded_msg->supported_messages == NULL) {
  456. free(u16a);
  457. return (-2);
  458. }
  459. for (zi = 0; zi < decoded_msg->no_supported_messages; zi++) {
  460. decoded_msg->supported_messages[zi] = (enum msg_type)u16a[zi];
  461. }
  462. free(u16a);
  463. break;
  464. case TLV_OPT_SUPPORTED_OPTIONS:
  465. free(decoded_msg->supported_options);
  466. if ((res = tlv_iter_decode_supported_options(&tlv_iter, &decoded_msg->supported_options,
  467. &decoded_msg->no_supported_options)) != 0) {
  468. return (res);
  469. }
  470. break;
  471. case TLV_OPT_REPLY_ERROR_CODE:
  472. if (tlv_iter_decode_reply_error_code(&tlv_iter, &decoded_msg->reply_error_code) != 0) {
  473. return (-1);
  474. }
  475. decoded_msg->reply_error_code_set = 1;
  476. break;
  477. case TLV_OPT_SERVER_MAXIMUM_REQUEST_SIZE:
  478. if (tlv_iter_decode_u32(&tlv_iter, &u32) != 0) {
  479. return (-1);
  480. }
  481. decoded_msg->server_maximum_request_size_set = 1;
  482. decoded_msg->server_maximum_request_size = u32;
  483. break;
  484. case TLV_OPT_SERVER_MAXIMUM_REPLY_SIZE:
  485. if (tlv_iter_decode_u32(&tlv_iter, &u32) != 0) {
  486. return (-1);
  487. }
  488. decoded_msg->server_maximum_reply_size_set = 1;
  489. decoded_msg->server_maximum_reply_size = u32;
  490. break;
  491. case TLV_OPT_NODE_ID:
  492. if (tlv_iter_decode_u32(&tlv_iter, &u32) != 0) {
  493. return (-1);
  494. }
  495. decoded_msg->node_id_set = 1;
  496. decoded_msg->node_id = u32;
  497. break;
  498. case TLV_OPT_SUPPORTED_DECISION_ALGORITHMS:
  499. free(decoded_msg->supported_decision_algorithms);
  500. if ((res = tlv_iter_decode_supported_decision_algorithms(&tlv_iter,
  501. &decoded_msg->supported_decision_algorithms,
  502. &decoded_msg->no_supported_decision_algorithms)) != 0) {
  503. return (res);
  504. }
  505. break;
  506. case TLV_OPT_DECISION_ALGORITHM:
  507. if (tlv_iter_decode_decision_algorithm(&tlv_iter, &decoded_msg->decision_algorithm) != 0) {
  508. return (-1);
  509. }
  510. decoded_msg->decision_algorithm_set = 1;
  511. break;
  512. case TLV_OPT_HEARTBEAT_INTERVAL:
  513. if (tlv_iter_decode_u32(&tlv_iter, &u32) != 0) {
  514. return (-1);
  515. }
  516. decoded_msg->heartbeat_interval_set = 1;
  517. decoded_msg->heartbeat_interval = u32;
  518. break;
  519. default:
  520. /*
  521. * Unknown option
  522. */
  523. break;
  524. }
  525. }
  526. if (iter_res != 0) {
  527. return (-3);
  528. }
  529. return (0);
  530. }
  531. void
  532. msg_get_supported_messages(enum msg_type **supported_messages, size_t *no_supported_messages)
  533. {
  534. *supported_messages = msg_static_supported_messages;
  535. *no_supported_messages = MSG_STATIC_SUPPORTED_MESSAGES_SIZE;
  536. }