Skip to content

Add logic for instantiating UdpListenSocket based on SocketAddress.protocol in listener config#5443

Merged
mattklein123 merged 12 commits intoenvoyproxy:masterfrom
mpwarres:listener_socket_type
Jan 6, 2019
Merged

Add logic for instantiating UdpListenSocket based on SocketAddress.protocol in listener config#5443
mattklein123 merged 12 commits intoenvoyproxy:masterfrom
mpwarres:listener_socket_type

Conversation

@mpwarres
Copy link
Contributor

Description:

Assorted plumbing to instantiate UdpListenSocket based on SocketAddress.protocol in listener config, and make the fact that it is a datagram socket visible to consuming code:

  • Add Network::Utility::protobufAddressSocketType() function, for fetching
    SocketAddress.protocol values from listener config and translating to
    Network::Address::SocketType values.

  • Modify Server::ListenerImpl to fetch SocketAddress.protocol value.

  • Modify Config::AddressJson::translateAddress() to set SocketAddress.protocol
    based on URL scheme.

  • Add Network::Address::SocketType param to
    ListenerComponentFactory::createListenSocket(), to allow caller to indicate
    whether a TCP or UDP socket (or a Unix domain socket) should be created.

  • Add Socket::socketType() accessor, so code using a socket can determine
    whether it is a stream or datagram socket.

With these changes, when a Listener is configured with
SocketAddress.protocol=UDP (either directly in protobuf or in JSON via udp://
URL), the listen socket created by
Server::ListenerManagerImpl::addOrUpdateListener() will be a UdpListenSocket,
and code that acts on the socket (e.g. Server::WorkerImpl::addListener(),
Server::ConnectionHandlerImpl::addListener()) can branch on socket type to set
up appropriate event notification and handling.

Risk Level: Low
Testing: Unit tests added
Docs Changes: N/A
Release Notes: N/A
[Optional Fixes #Issue]
[Optional Deprecated:]

Also add Server::ListenerImpl::socket_type_ field and accessor.

Signed-off-by: Michael Warres <mpw@google.com>
…on URL scheme.

Signed-off-by: Michael Warres <mpw@google.com>
Signed-off-by: Michael Warres <mpw@google.com>
Signed-off-by: Michael Warres <mpw@google.com>
Signed-off-by: Michael Warres <mpw@google.com>
@mpwarres
Copy link
Contributor Author

@conqerAtapple @mattklein123 @alyssawilk @cmluciano

Here is some (non-QUIC-specific) config plumbing needed for prototyping the QUIC listener that should hopefully also help with @conqerAtapple PR #5256. I think this should be ready for review.

Signed-off-by: Michael Warres <mpw@google.com>
@alyssawilk alyssawilk assigned alyssawilk and unassigned alyssawilk Jan 2, 2019
Copy link
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

Hoping @conqerAtapple can do a pass as well just to make sure you two are aligned on UDP plans

Signed-off-by: Michael Warres <mpw@google.com>
@mpwarres
Copy link
Contributor Author

mpwarres commented Jan 2, 2019

Thanks for the review, Alyssa! Agree it would be good for @conqerAtapple to take a look to make sure this is compatible with what he's doing. I think it should fit in nicely with PR #5256 in that this code gets the UdpListenSocket instantiated, and then #5256 takes it from there, but we'll see.

@conqerAtapple
Copy link
Contributor

@mpwarres @alyssawilk Thanks for checking. So far @mpwarres changes looks to be fine/orthogonal to the UDP proxy changes I have been working on.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks very cool. One small drive by comment.

Modify ListenerManagerImplWithRealFiltersTest.UdpAddress to specify listener
protobuf directly via protobuf text format, rather than deprecated JSON format.

Signed-off-by: Michael Warres <mpw@google.com>
@mattklein123
Copy link
Member

@mpwarres check CI?

/wait

@mattklein123 mattklein123 self-assigned this Jan 4, 2019
…:translateAddress() changes.

Signed-off-by: Michael Warres <mpw@google.com>
@mpwarres
Copy link
Contributor Author

mpwarres commented Jan 4, 2019

Oops! Forgot to revert a test when backing out the AddressJson::translateAddress() change. Should hopefully pass CI now.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM, few small things.

/wait

case envoy::api::v2::core::SocketAddress::UDP:
return Address::SocketType::Datagram;
default:
throw EnvoyException(fmt::format("unknown protocol value: {}", protocol));
Copy link
Member

Choose a reason for hiding this comment

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

Can this actually happen? Is that caught by proto validation such that the default can be not reached?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, got it, hadn't realized we can assume validation has occurred. Replaced with NOT_REACHED_GCOVR_EXCL_LINE.

return "SocketType::Stream";
case Network::Address::SocketType::Datagram:
return "SocketType::Datagram";
default:
Copy link
Member

Choose a reason for hiding this comment

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

I think this case is not needed as the compiler will check all enums are handled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, fixed. Thanks!

Signed-off-by: Michael Warres <mpw@google.com>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks!

@mattklein123 mattklein123 merged commit 7c5badb into envoyproxy:master Jan 6, 2019
@mpwarres mpwarres deleted the listener_socket_type branch January 6, 2019 18:42
@mpwarres
Copy link
Contributor Author

Tagging associated issues #492 and #2557

fredlas pushed a commit to fredlas/envoy that referenced this pull request Mar 5, 2019
…otocol in listener config (envoyproxy#5443)

Signed-off-by: Michael Warres <mpw@google.com>
Signed-off-by: Fred Douglas <fredlas@google.com>
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.

4 participants