Skip to content

IoHandle: add interfaceName() method#18531

Merged
junr03 merged 24 commits intomainfrom
interface-name
Dec 20, 2021
Merged

IoHandle: add interfaceName() method#18531
junr03 merged 24 commits intomainfrom
interface-name

Conversation

@junr03
Copy link
Copy Markdown
Member

@junr03 junr03 commented Oct 8, 2021

Commit Message: IoHandle - add interfaceName() method.
Additional Description: returns the interface name for the underlying socket if the implementation and OS allows. This is done by matching the sockets local address to the address of interfaces as returned by getifaddrs.
Risk Level: low
Testing: pending UT

Signed-off-by: Jose Nino jnino@lyft.com

Jose Nino added 2 commits October 7, 2021 22:03
wip
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03
Copy link
Copy Markdown
Member Author

junr03 commented Oct 8, 2021

@mattklein123 @goaway I am figuring out how to test this reliably on CI. I think using the loopback interface and address might be the best route. Will update ASAP.

I mainly wanted to get out quick so @goaway could comment on if this is the direction he wanted this piece of work to go on.

Jose Nino added 2 commits October 8, 2021 10:55
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03
Copy link
Copy Markdown
Member Author

junr03 commented Oct 8, 2021

@goaway @mattklein123 this is ready for review!

Jose Nino added 3 commits October 8, 2021 13:05
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
mattklein123
mattklein123 previously approved these changes Oct 8, 2021
Copy link
Copy Markdown
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 LGTM. Not sure if you want to merge the other PR first or fix up that PR based on this one?


absl::optional<std::string> IoSocketHandleImpl::interfaceName() {
absl::optional<std::string> selected_interface_name{};
#ifdef SUPPORTS_GETIFADDRS
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will this change based on the other other PR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep. This will change to use the other PR (#18513) and prevent the ifdefs and direct syscalls.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The windows failure can also be solved with ^.

Jose Nino added 3 commits October 8, 2021 15:16
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
Jose Nino added 3 commits October 10, 2021 19:14
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
EXPECT_FALSE(maybe_interface_name.has_value());
}

TEST(IoSocketHandleImpl, InterfaceNameForLoopbackExplicitV6) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The test below was not showing coverage for v6. Testing here explicitly.

mattklein123
mattklein123 previously approved these changes Oct 11, 2021
Copy link
Copy Markdown
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, LGTM.

@junr03
Copy link
Copy Markdown
Member Author

junr03 commented Oct 11, 2021

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #18531 (comment) was created by @junr03.

see: more, trace.

Jose Nino added 2 commits October 12, 2021 08:43
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
mattklein123
mattklein123 previously approved these changes Oct 12, 2021
@github-actions github-actions bot closed this Nov 19, 2021
@mattklein123 mattklein123 deleted the interface-name branch November 19, 2021 23:02
@junr03 junr03 restored the interface-name branch December 8, 2021 18:01
Jose Nino added 2 commits December 8, 2021 10:15
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03 junr03 removed the stale stalebot believes this issue/PR has not been touched recently label Dec 9, 2021
Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03 junr03 requested a review from rojkov as a code owner December 9, 2021 00:55

Api::SysCallIntResult shutdown(int how) override;
absl::optional<std::chrono::milliseconds> lastRoundTripTime() override { return absl::nullopt; }
absl::optional<std::string> interfaceName() override { return absl::nullopt; }
Copy link
Copy Markdown
Member Author

@junr03 junr03 Dec 9, 2021

Choose a reason for hiding this comment

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

@florincoras @rojkov I believe the same implementation that I wrote (above) for the IoSocketHandleImpl would work here. Do you think it would be worth it to move the implementation to the virtual class? Given that the implementation is based on localAddress() and the os syscalls available it doesn't seem like it would necessarily need to be outside of the virtual class.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The virtual class is supposed to be just an interface enforcing concrete implementations at compile-time like this trivial stub. Otherwise there's a chance of calling a suboptimal implementation (which e.g. checks os syscall availability first). And in this particular case it could be even an error if something called a user space handle's interfaceName().

But I agree the implementation should be shared somehow where it makes sense. In #19082 I'll need the same code. Even more to that - I need the same implementation for localAddress() and peerAddress(). Maybe utility functions would suffice?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed with @rojkov. It won't also work for vcl because the interfaces are in another user space process (vpp), so not available via syscalls.

The idea might not be too bright but one could argue that there should've been a syscall to get a socket's localAddress(), peerAddress() and the interfaceName for a localAddress(), so one option would be to add these utility functions to syscall interfaces. The downside however is that we'll pollute those with non-posix apis.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@rojkov @florincoras thanks for your thoughtful responses. It makes sense to me. I also realize how little experience I have of this line of work. If you dont think that the current addition to the interface is egregious, do you all mind if I implement here as is and let you all handle this when/if you tackle moving localAddress() and peerAddress around?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't, I'm fine with it as it is for now.

Jose Nino added 2 commits December 9, 2021 12:51
Signed-off-by: Jose Nino <jnino@lyft.com>
fmt
Signed-off-by: Jose Nino <jnino@lyft.com>
@goaway
Copy link
Copy Markdown
Contributor

goaway commented Dec 15, 2021

Overall this looks good from an EM perspective. Left one nit comment. Thanks @junr03!

Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03
Copy link
Copy Markdown
Member Author

junr03 commented Dec 15, 2021

@rojkov do you mind doing a pass on this?

@junr03
Copy link
Copy Markdown
Member Author

junr03 commented Dec 16, 2021

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #18531 (comment) was created by @junr03.

see: more, trace.

Copy link
Copy Markdown
Member

@rojkov rojkov left a comment

Choose a reason for hiding this comment

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

This looks good! I added a couple of questions to clarify.

Signed-off-by: Jose Nino <jnino@lyft.com>
Copy link
Copy Markdown
Member

@rojkov rojkov left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@junr03 junr03 merged commit 6957172 into main Dec 20, 2021
rgs1 pushed a commit to rgs1/envoy that referenced this pull request Jan 7, 2022
Was reading through envoyproxy#18531 and seeing the socket address being looked
up for each interface confused me a bit, so let's do it only once.

Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
@junr03 junr03 deleted the interface-name branch January 11, 2022 18:41
joshperry pushed a commit to joshperry/envoy that referenced this pull request Feb 13, 2022
Commit Message: IoHandle - add interfaceName() method.
Additional Description: returns the interface name for the underlying socket if the implementation and OS allows. This is done by matching the sockets local address to the address of interfaces as returned by getifaddrs.
Risk Level: low
Testing: pending UT

Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Josh Perry <josh.perry@mx.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.

5 participants