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

Prevent loss of m_ipv6_socket attribute #181

Merged
merged 1 commit into from Jun 9, 2019

Conversation

vladmovchan
Copy link
Contributor

SocketFd::accept() always returns SocketFd object with m_ipv6_socket flag set to false.
As the result SocketFd::set_priority() which called later on the same socket executes

setsockopt(m_fd, IPPROTO_IP, IP_TOS, &opt, sizeof(opt))

even for IPv6 sockets.

Linux tolerates this, but on FreeBSD such call on IPv6 socket cause error, and as the result following call chain fails:

frame #0: 0x0000000800595d72 libtorrent.so.20.0.0`torrent::SocketFd::set_priority(unsigned char) + 114
frame #1: 0x000000080059e05d libtorrent.so.20.0.0`torrent::HandshakeManager::setup_socket(torrent::SocketFd) + 125
frame #2: 0x000000080059deca libtorrent.so.20.0.0`torrent::HandshakeManager::add_incoming(torrent::SocketFd, rak::socket_address const&) + 90
frame #3: 0x000000080059562e libtorrent.so.20.0.0`torrent::Listen::event_read(void) + 94
frame #4: 0x000000080052d974 libtorrent.so.20.0.0`torrent::PollKQueue::perform(void) + 68
frame #5: 0x0000000800561a83 libtorrent.so.20.0.0`torrent::thread_base::event_loop(torrent::thread_base*) + 387

what causes immediate drop of any incoming connection right after it has been accept()-ed.

Syscall trace of this case on FreeBSD host:

accept(12,{ AF_INET6 [::ffff:127.0.0.1]:28543 },0x7fffffffddfc) = 161 (0xa1)
fcntl(161,F_SETFL,O_RDONLY|O_NONBLOCK)		 = 0 (0x0)
setsockopt(161,IPPROTO_IP,IP_TOS,0x7fffffffdd9c,4) ERR#22 'Invalid argument'
close(161)					 = 0 (0x0)

For comparison same trace on CentOS 7 host:

[pid 15592] accept(13, {sa_family=AF_INET6, sin6_port=htons(60668), inet_pton(AF_INET6, "::ffff:127.0.0.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 16
[pid 15592] fcntl(16, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
[pid 15592] setsockopt(16, SOL_IP, IP_TOS, [8], 4) = 0

This change fixes rakshasa/rtorrent#786

setsockopt(..., IPPROTO_IP, IP_TOS, ...) on IPv6 socket
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 17.873% when pulling 0f957c2 on vladmovchan:IPv6_patch into 3a6a61a on rakshasa:master.

@glebius
Copy link
Contributor

glebius commented Jan 23, 2019

Pretty sure the same problem as in pull request #179 . Not sure whose patch is better. I already don't remember details.

@rakshasa rakshasa merged commit 0f957c2 into rakshasa:master Jun 9, 2019
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.

Incoming connections broken on FreeBSD
4 participants