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

WIP: PR for allowing hostnames in config files #42

Open
wants to merge 2 commits into
base: auterion-router-latest
Choose a base branch
from

Conversation

radarku
Copy link

@radarku radarku commented May 20, 2022

Objective

To allow specification of hostnames (rather than just IP addresses) in mavlink-router config files.

Context

It seems as if this feature isn't part of the upstream mavlink-router yet, either, but we're looking to be able to specify a hostname that can be resolved dynamically at runtime.

The goal would be to allow configurations such as the following:

[UdpEndpoint qgroundcontrol]
Mode = Eavesdropping
Address = qgc.auterion.com
Port = 14551

The current result when using this config is:

Invalid IP address in section UdpEndpoint qgroundcontrol: qgc.auterion.com

Current Status

Note that this initial patch is a WIP (i.e., it does not seem to add the feature properly); it was my best stab at making it work. @TSC21 suggested I open a PR to get some feedback/help. Thanks!

@radarku
Copy link
Author

radarku commented May 25, 2022

@TSC21 Can you tag anyone that you think may be able to help on this PR, please? Thanks!

src/mavlink-router/endpoint.cpp Outdated Show resolved Hide resolved
@@ -797,14 +797,9 @@ static int parse_confs(ConfFile &conf)
log_error("Expected 'port' key for section %.*s", (int)iter.name_len, iter.name);
ret = -EINVAL;
} else {
if (validate_ip(opt_udp.addr) < 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens now if the ip/hostname is invalid? Does it crash somewhere, or does it just not work? Wouldn't it be nicer to have an error message similar to the one removed here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that it would be better to keep the validation check, but it looks like the check for valid hostnames can be quite extensive per RFC1123; maybe better to defer it to the hostname lookup stage?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then won't it fail in the getaddrinfo call (line 1169)? Shouldn't it print an error message (some log_error()) there? Right now it feels like it just does exit(1), so we won't know what happened from the logs, right? Or did I miss something?

Comment on lines 1184 to 1186
#ifdef ENABLE_IPV6
}
#endif

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that compile when ENABLE_IPV6 is enabled? Feels like you removed the opening bracket 🤔

@@ -797,14 +797,9 @@ static int parse_confs(ConfFile &conf)
log_error("Expected 'port' key for section %.*s", (int)iter.name_len, iter.name);
ret = -EINVAL;
} else {
if (validate_ip(opt_udp.addr) < 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then won't it fail in the getaddrinfo call (line 1169)? Shouldn't it print an error message (some log_error()) there? Right now it feels like it just does exit(1), so we won't know what happened from the logs, right? Or did I miss something?

Comment on lines +1188 to +1202
// #ifdef ENABLE_IPV6
// if (this->is_ipv6) {
// if (connect(fd, (struct sockaddr *)&sockaddr6, sizeof(sockaddr6)) < 0) {
// log_error("Error connecting to IPv6 socket (%m)");
// goto fail;
// }
// } else {
// #endif
// if (connect(fd, addrs[0]->ai_addr, addrs[0]->ai_addrlen) < 0) {
// log_error("Error connecting to socket (%m)");
// goto fail;
// }
// #ifdef ENABLE_IPV6
// }
// #endif

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// #ifdef ENABLE_IPV6
// if (this->is_ipv6) {
// if (connect(fd, (struct sockaddr *)&sockaddr6, sizeof(sockaddr6)) < 0) {
// log_error("Error connecting to IPv6 socket (%m)");
// goto fail;
// }
// } else {
// #endif
// if (connect(fd, addrs[0]->ai_addr, addrs[0]->ai_addrlen) < 0) {
// log_error("Error connecting to socket (%m)");
// goto fail;
// }
// #ifdef ENABLE_IPV6
// }
// #endif


struct addrinfo hints = {0}, *addrs;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a UdpEndpoint, shouldn't that be a SOCK_DGRAM?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants