Skip to content

tcp: Redefined bind => listen and support for virtual IPs#1257

Merged
alfreb merged 5 commits intoincludeos:devfrom
AndreasAakesson:dev
Mar 23, 2017
Merged

tcp: Redefined bind => listen and support for virtual IPs#1257
alfreb merged 5 commits intoincludeos:devfrom
AndreasAakesson:dev

Conversation

@AndreasAakesson
Copy link
Copy Markdown
Contributor

bind() is now an internal thing for TCP. What was earlier bind is now listen().

It's now possible to set source address or source socket on both listen() and connect(). These may throw if they are unable to bind to the socket/address. Still missing the wiring with Inet, but added pseudo code: TCP::validate_address(ip4::Addr).

Copy link
Copy Markdown
Contributor

@alfreb alfreb left a comment

Choose a reason for hiding this comment

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

Nice! Will give us more options for virtual IP's, loopback etc. Only issue afaict is that it's now possible to bind to any address.

Comment thread src/net/tcp/tcp.cpp
// TODO: Avoid wrap around, increment ephemeral to next free port.
// while(is_bound(ephemeral_)) ++ephemeral_; // worst case is like 16k iterations :D
// need a solution that checks each word of the subset (the dynamic range)
Ensures(is_bound(ephemeral_) == false && "Hoped I wouldn't see the day..."); // this may happen...
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.

😂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Feel free to dig in xD

Comment thread src/net/tcp/tcp.cpp Outdated
// Stat increment packets dropped
packets_dropped_++;
debug("<TCP::drop> Packet dropped\n");
// TODO:
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.

I'll add inet::is_valid_source(IP4::addr)

Comment thread src/net/tcp/tcp.cpp Outdated
// Stat increment packets dropped
packets_dropped_++;
debug("<TCP::drop> Packet dropped\n");
// TODO:
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.

I'll add Inet::is_valid_source(IP4::addr)

Comment thread src/net/tcp/tcp.cpp Outdated
std::make_unique<tcp::Listener>(*this, socket, std::move(cb))
).first->second;
debug("<TCP::bind> Bound to port %i \n", port);
debug("<TCP::bind> Bound to socket %s \n", socket.to_string());
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.

TCP::listen

Comment thread src/net/tcp/tcp.cpp
}
auto& listener = listeners_.emplace(port,
std::make_unique<tcp::Listener>(*this, port, std::move(cb))
bind(socket);
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.

What will happen on TCP::listen({{8, 8, 8, 8}, 80}? I think bind to socket has to verify the source IP with inet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment thread api/net/tcp/tcp.hpp
* @brief Validate the address by making sure it's allowed in this context.
*
* @param[in] addr The address
*/
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.

Maybe refactor to validate_source(... addr)?

Comment thread src/net/tcp/tcp.cpp
{
if (UNLIKELY( is_bound(socket) ))
throw TCP_error{"Socket is already in use: " + socket.to_string()};

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.

I think you need to call validate_address here.

@alfreb alfreb merged commit 1e5f8eb into includeos:dev Mar 23, 2017
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