Skip to content

halrmt: Allow IPv4 as fallback when IPv6 is disabled. - #4405

Open
BsAtHome wants to merge 1 commit into
LinuxCNC:masterfrom
BsAtHome:fix_halrmt-ipv4
Open

halrmt: Allow IPv4 as fallback when IPv6 is disabled.#4405
BsAtHome wants to merge 1 commit into
LinuxCNC:masterfrom
BsAtHome:fix_halrmt-ipv4

Conversation

@BsAtHome

Copy link
Copy Markdown
Contributor

The new halrmt server uses v4-mapped-on-v6 to have one socket accept both IPv6 and IPv4 connections. However, if IPv6 is disabled at the kernel command line (or not compiled in), then it would fail to create a listening socket. This PR adds an IPv4-only fallback in case IPv6 fails.

Comment thread src/hal/utils/halrmt.cc
return -1;
}
}
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as #4403: this depends on net.ipv6.bindv6only being 0. With that sysctl at
1, socket(AF_INET6, ...) succeeds so the fallback never fires and IPv4 clients
get ECONNREFUSED. Confirmed:

v6only=0  IPv4 client: connected OK
v6only=1  IPv4 client: connect FAILED (Connection refused)

Explicit setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, &zero, ...) on the IPv6
branch?

Comment thread src/hal/utils/halrmt.cc
addr.addr6.sin6_port = htons(port);
socklen_t slen = sizeof(addr.addr6);

sockfd = socket(AF_INET6, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is EAFNOSUPPORT the only failure worth falling back on? EACCES/EPERM from a
restricted netns or LSM policy reach the same point, and bind() to :: can fail
independently of socket(). Reason not to fall back on any IPv6 failure?

Comment thread src/hal/utils/halrmt.cc
struct sockaddr_in6 csa6;
struct sockaddr_in csa4;
} csa;
socklen_t csal = isipv4 ? sizeof(csa.csa4) : sizeof(csa.csa6);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

accept4() writes the real length back, so sizeof(csa) works for both families.
Would sockaddr_storage plus getnameinfo(..., NI_NUMERICHOST | NI_NUMERICSERV)
remove the union, isipv4, and the duplicated logging branch below altogether?

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