void test_channel_proto_get_set_unset(void) { lagopus_result_t ret; struct channel *channel; enum channel_protocol protocol; channel = s_create_data_channel(); ret = channel_protocol_set(channel, PROTOCOL_TCP6); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "channel_protocol_set() error."); ret = channel_protocol_get(channel, &protocol); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "channel_protocol_get() error."); TEST_ASSERT_EQUAL_MESSAGE(PROTOCOL_TCP6, protocol, "channel_protocol_get() proto error"); ret = channel_protocol_unset(channel); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "channel_protocol_unset() error."); ret = channel_protocol_get(channel, &protocol); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "channel_protocol_get() error."); TEST_ASSERT_EQUAL_MESSAGE(PROTOCOL_TCP, protocol, "channel_protocol_get() proto error"); session_destroy(channel_session_get(channel)); free(channel); }
lagopus_result_t channel_mgr_channel_tls_add(const char *bridge_name, uint64_t dpid, struct addrunion *addr) { lagopus_result_t ret; struct channel *chan = NULL; ret = channel_mgr_channel_add_internal(bridge_name, dpid, addr, &chan); if (ret != LAGOPUS_RESULT_OK) { return ret; } lagopus_msg_debug(10, "channel %p protocol set\n", chan); ret = channel_protocol_set(chan, PROTOCOL_TLS); if (ret != LAGOPUS_RESULT_OK) { channel_mgr_channel_delete(bridge_name, addr); return ret; } lagopus_msg_debug(10, "channel %p enabled\n", chan); channel_enable(chan); return ret; }
lagopus_result_t channel_mgr_channel_create(const char *channel_name, lagopus_ip_address_t *dst_addr, uint16_t dst_port, lagopus_ip_address_t *src_addr, uint16_t src_port, datastore_channel_protocol_t protocol) { lagopus_result_t ret; struct channel *chan = NULL; struct sockaddr *sa; struct sockaddr_storage ss = {0}; struct addrunion daddr = {0}, saddr = {0}; enum channel_protocol cprotocol; sa = (struct sockaddr *) &ss; ret = lagopus_ip_address_sockaddr_get(dst_addr, &sa); if (ret != LAGOPUS_RESULT_OK) { return ret; } sockaddr_to_addrunion(sa, &daddr); ret = channel_add_internal(channel_name, &daddr, &chan); if (ret != LAGOPUS_RESULT_OK) { return ret; } ret = channel_port_set(chan, dst_port); if (ret != LAGOPUS_RESULT_OK) { goto fail; } if (src_addr != NULL) { ret = lagopus_ip_address_sockaddr_get(src_addr, &sa); if (ret != LAGOPUS_RESULT_OK) { goto fail; } sockaddr_to_addrunion(sa, &saddr); ret = channel_local_addr_set(chan, &saddr); if (ret != LAGOPUS_RESULT_OK) { goto fail; } } ret = channel_local_port_set(chan, src_port); if (ret != LAGOPUS_RESULT_OK) { goto fail; } switch (protocol) { case DATASTORE_CHANNEL_PROTOCOL_TCP: cprotocol = PROTOCOL_TCP; break; case DATASTORE_CHANNEL_PROTOCOL_TLS: cprotocol = PROTOCOL_TLS; break; default: return LAGOPUS_RESULT_INVALID_ARGS; } ret = channel_protocol_set(chan, cprotocol); if (ret != LAGOPUS_RESULT_OK) { goto fail; } return LAGOPUS_RESULT_OK; fail: channel_delete_internal(channel_name); return ret; }