Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change port from uint16_t to uint32_t, to support VSOCK #338

Merged
merged 7 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/elastipubsub/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct app_ctx {
struct aws_mutex lock;
struct aws_condition_variable signal;
struct aws_uri uri;
uint16_t port;
uint32_t port;
const char *cacert;
const char *cert;
const char *key;
Expand Down
2 changes: 1 addition & 1 deletion bin/elastipubsub5/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct app_ctx {
struct aws_mutex lock;
struct aws_condition_variable signal;
struct aws_uri uri;
uint16_t port;
uint32_t port;
const char *cacert;
const char *cert;
const char *key;
Expand Down
4 changes: 2 additions & 2 deletions bin/mqtt5canary/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct app_ctx {
struct aws_mutex lock;
struct aws_condition_variable signal;
struct aws_uri uri;
uint16_t port;
uint32_t port;
const char *cacert;
const char *cert;
const char *key;
Expand Down Expand Up @@ -181,7 +181,7 @@ static void s_parse_options(
ctx->use_websockets = true;
break;
case 'p':
ctx->port = (uint16_t)atoi(aws_cli_optarg);
ctx->port = (uint32_t)atoi(aws_cli_optarg);
break;
case 't':
tester_options->elg_max_threads = (uint16_t)atoi(aws_cli_optarg);
Expand Down
2 changes: 1 addition & 1 deletion include/aws/mqtt/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ struct aws_mqtt_topic_subscription {
*/
struct aws_mqtt_connection_options {
struct aws_byte_cursor host_name;
uint16_t port;
uint32_t port;
struct aws_socket_options *socket_options;
struct aws_tls_connection_options *tls_options;
struct aws_byte_cursor client_id;
Expand Down
2 changes: 1 addition & 1 deletion include/aws/mqtt/private/client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ struct aws_mqtt_client_connection_311_impl {

/* The host information, changed by user when state is AWS_MQTT_CLIENT_STATE_DISCONNECTED */
struct aws_string *host_name;
uint16_t port;
uint32_t port;
struct aws_tls_connection_options tls_options;
struct aws_socket_options socket_options;
struct aws_http_proxy_config *http_proxy_config;
Expand Down
2 changes: 1 addition & 1 deletion include/aws/mqtt/private/v5/mqtt5_options_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct aws_mqtt5_client_options_storage {
struct aws_allocator *allocator;

struct aws_string *host_name;
uint16_t port;
uint32_t port;
struct aws_client_bootstrap *bootstrap;
struct aws_socket_options socket_options;

Expand Down
2 changes: 1 addition & 1 deletion include/aws/mqtt/v5/mqtt5_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ struct aws_mqtt5_client_options {
/**
* Port to establish mqtt connections to
*/
uint16_t port;
uint32_t port;

/**
* Client bootstrap to use whenever this client establishes a connection
Expand Down
14 changes: 10 additions & 4 deletions source/v5/mqtt5_options_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -3356,14 +3356,20 @@ int aws_mqtt5_client_options_validate(const struct aws_mqtt5_client_options *opt
}
}

if (aws_socket_validate_port_for_connect(
options->port, options->socket_options ? options->socket_options->domain : AWS_SOCKET_IPV4)) {
AWS_LOGF_ERROR(AWS_LS_MQTT5_GENERAL, "invalid port in mqtt5 client configuration");
return aws_raise_error(AWS_ERROR_MQTT5_CLIENT_OPTIONS_VALIDATION);
}

if (options->http_proxy_options != NULL) {
if (options->http_proxy_options->host.len == 0) {
AWS_LOGF_ERROR(AWS_LS_MQTT5_GENERAL, "proxy host name not set in mqtt5 client configuration");
return aws_raise_error(AWS_ERROR_MQTT5_CLIENT_OPTIONS_VALIDATION);
}

if (options->http_proxy_options->port == 0) {
AWS_LOGF_ERROR(AWS_LS_MQTT5_GENERAL, "proxy port not set in mqtt5 client configuration");
if (aws_socket_validate_port_for_connect(options->http_proxy_options->port, AWS_SOCKET_IPV4)) {
AWS_LOGF_ERROR(AWS_LS_MQTT5_GENERAL, "invalid proxy port in mqtt5 client configuration");
return aws_raise_error(AWS_ERROR_MQTT5_CLIENT_OPTIONS_VALIDATION);
}
}
Expand Down Expand Up @@ -3542,7 +3548,7 @@ void aws_mqtt5_client_options_storage_log(
log_handle,
level,
AWS_LS_MQTT5_GENERAL,
"id=%p: aws_mqtt5_client_options_storage port set to %" PRIu16,
"id=%p: aws_mqtt5_client_options_storage port set to %" PRIu32,
(void *)options_storage,
options_storage->port);

Expand Down Expand Up @@ -3603,7 +3609,7 @@ void aws_mqtt5_client_options_storage_log(
log_handle,
level,
AWS_LS_MQTT5_GENERAL,
"id=%p: aws_mqtt5_client_options_storage http proxy port set to %" PRIu16,
"id=%p: aws_mqtt5_client_options_storage http proxy port set to %" PRIu32,
(void *)options_storage,
options_storage->http_proxy_options.port);

Expand Down
2 changes: 1 addition & 1 deletion source/v5/mqtt5_to_mqtt3_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ struct aws_mqtt_adapter_connect_task {
struct aws_mqtt_client_connection_5_impl *adapter;

struct aws_byte_buf host_name;
uint16_t port;
uint32_t port;
struct aws_socket_options socket_options;
struct aws_tls_connection_options *tls_options_ptr;
struct aws_tls_connection_options tls_options;
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ add_test_case(mqtt5_client_options_validation_failure_no_publish_received)
add_test_case(mqtt5_client_options_validation_failure_invalid_socket_options)
add_test_case(mqtt5_client_options_validation_failure_invalid_connect)
add_test_case(mqtt5_client_options_validation_failure_invalid_keep_alive)
add_test_case(mqtt5_client_options_validation_failure_invalid_port)
add_test_case(mqtt5_operation_subscribe_connection_settings_validation_failure_exceeds_maximum_packet_size)
add_test_case(mqtt5_operation_unsubscribe_connection_settings_validation_failure_exceeds_maximum_packet_size)
add_test_case(mqtt5_operation_publish_connection_settings_validation_failure_exceeds_maximum_packet_size)
Expand Down
7 changes: 7 additions & 0 deletions tests/v5/mqtt5_operation_validation_failure_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,7 @@ static struct aws_mqtt5_client_options s_good_client_options = {
.ptr = s_server_reference,
.len = AWS_ARRAY_SIZE(s_server_reference) - 1,
},
.port = 1883,
.socket_options = &s_good_socket_options,
.connect_options = &s_good_connect,
.ping_timeout_ms = 5000,
Expand Down Expand Up @@ -1183,6 +1184,12 @@ AWS_CLIENT_CREATION_VALIDATION_FAILURE(
s_good_client_options,
s_make_invalid_keep_alive_client_options)

static void s_make_invalid_port_client_options(struct aws_mqtt5_client_options *options) {
options->port = 0xFFFFFFFF;
}

AWS_CLIENT_CREATION_VALIDATION_FAILURE(invalid_port, s_good_client_options, s_make_invalid_port_client_options)

#define AWS_CONNECTION_SETTINGS_VALIDATION_FAILURE_TEST_PREFIX(packet_type, failure_reason, init_success_settings_fn) \
static int s_mqtt5_operation_##packet_type##_connection_settings_validation_failure_##failure_reason##_fn( \
struct aws_allocator *allocator, void *ctx) { \
Expand Down