Skip to content

Conversation

@rzikm
Copy link
Member

@rzikm rzikm commented Mar 17, 2022

This PR replaces duplicated code for composing OS-level SOCKADDR_INET structure by preexisting code in SocketAddress class.

Fixes #32068

@ghost
Copy link

ghost commented Mar 18, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

This PR replaces duplicated code for composing OS-level SOCKADDR_INET structure by preexisting code in SocketAddress class.

Fixes #32068

Author: rzikm
Assignees: rzikm
Labels:

area-System.Net

Milestone: -

@ghost
Copy link

ghost commented Mar 21, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

This PR replaces duplicated code for composing OS-level SOCKADDR_INET structure by preexisting code in SocketAddress class.

Fixes #32068

Author: rzikm
Assignees: rzikm
Labels:

area-System.Net, area-System.Net.Quic

Milestone: -

Copy link
Member

@ManickaP ManickaP left a comment

Choose a reason for hiding this comment

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

I gave a cursory look at the internal SocketAddress and I think we should invest in some optimization there and here together.
I might be looking wrongly, but it looks like this will introduce more copies of address bytes as well as more interop calls per each conversion (not necessarily meaning more allocations, though).

internal uint ListenerStart(SafeMsQuicListenerHandle listener, QuicBuffer* alpnBuffers, uint alpnBufferCount, byte* localAddress)
{
IntPtr __listener_gen_native = default;
IntPtr __listener_gen_native;
Copy link
Member

Choose a reason for hiding this comment

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

Why this line change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Compiler complained that the default-assigned value was never used

Copy link
Member

Choose a reason for hiding this comment

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

We still have it like that in other places since this is source generated code, so could we leave it as it was? Unless it breaks the build due to warnaserror or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

it breaks the build otherwise

Copy link
Member

Choose a reason for hiding this comment

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

Let's keep it then. It's still strange that the other methods or the previous version of this one didn't break the build.

value.Buffer.AsSpan(0, value.Size).CopyTo(address);
address.Slice(value.Size).Clear();

fixed (byte* paddress = &MemoryMarshal.GetReference(address))
Copy link
Member

Choose a reason for hiding this comment

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

Do we need pinning if the the source is stack allocated? I don't know the answer here, just asking. Or what does fixed here exactly do?

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't really do anything here, but the language requires you to use a fixed statement when "taking the address of an unfixed expression" like this.

Alternatively, it could be written as this (not saying it should be):

byte* pAddress = stackalloc byte[Internals.SocketAddress.IPv6AddressSize];
var address = new Span<byte>(pAddress, Internals.SocketAddress.IPv6AddressSize);

Copy link
Member

@wfurt wfurt left a comment

Choose a reason for hiding this comment

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

I'm wondering if this actually works with current quic e.g. 1.9. QUIC_ADDRESS_FAMILY.INET6 is same for all platforms but the new code will actually use the platform value AFAIK.

@rzikm
Copy link
Member Author

rzikm commented Mar 22, 2022

I'm wondering if this actually works with current quic e.g. 1.9. QUIC_ADDRESS_FAMILY.INET6 is same for all platforms but the new code will actually use the platform value AFAIK.

I thought that 1.9 is the one currently running as part of our CI, is it not, @ManickaP?

I manually downloaded 1.9 for local testing purposes and it worked on windows.

@ManickaP
Copy link
Member

QUIC_ADDRESS_FAMILY.INET6 is same for all platforms but the new code will actually use the platform value AFAIK

Nice catch, SocketAddress is using platform dependent values for INET = 2 and INET6 = 10 (on Linux) whereas QUIC_ADDRESS_FAMILY is using predefined constants: INET = 2 and INET6 = 23, which correspond to Windows values.
You should see it blow up if you try to use IPv6 on Linux with msquic 1.9.

I'm wondering whether this means that we don't have any coverage for IPv6 and we should probably add it.

@rzikm
Copy link
Member Author

rzikm commented Mar 23, 2022

QUIC_ADDRESS_FAMILY is using predefined constants: INET = 2 and INET6 = 23, which correspond to Windows values.

But we should be fine once we upgrade MsQuic, right? since latest MsQuic moved to platform-specific values again.

@ManickaP
Copy link
Member

But we should be fine once we upgrade MsQuic, right? since latest MsQuic moved to platform-specific values again.

yes

@rzikm rzikm requested a review from ManickaP March 28, 2022 08:54
@ManickaP
Copy link
Member

So to push this to a conclusion. Can we add tests for this:

I'm wondering whether this means that we don't have any coverage for IPv6 and we should probably add it.

If this change is expected to break for IPv6 and didn't actually blow anything up:

Then, an issue for this needs to be filed, against which the new test will be disabled. And finally, we'll resolve the issue with msquic 2.0 update (I already have some WIP so it shouldn't take much longer).

Does it sound reasonable @rzikm ?

@rzikm
Copy link
Member Author

rzikm commented Mar 29, 2022

I disabled tests broken by this change and filed #67301 for tracking broken IPv6 on Linux (to be closed after upgrade to MsQuic 2.0).

That should be enough to move this forward, right? @ManickaP?

Copy link
Member

@ManickaP ManickaP left a comment

Choose a reason for hiding this comment

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

Thanks!

@rzikm rzikm merged commit 38fe468 into dotnet:main Mar 30, 2022
@karelz karelz added this to the 7.0.0 milestone Apr 8, 2022
@ghost ghost locked as resolved and limited conversation to collaborators May 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[QUIC] Use shared SocketAddress code in QUIC

6 participants