-
-
Notifications
You must be signed in to change notification settings - Fork 128
FIX: response source address on [::]-bound servers are wrong #629
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
Merged
jkralik
merged 16 commits into
plgd-dev:master
from
Theoyor:fix/wildcard-address-wrong-srcaddr
Apr 2, 2026
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3785a05
fix: on binding the server to [::] the response happened to come from…
f8782d9
fix: add .idea to gitignore
b24bb25
feat: store source addr in conn
94fce92
fix: did not swap
b187e36
fix: remove vscode folder from gitignore
ec6f6e1
fix: ignore mcast adresses
7a6dfeb
fix: modify signatures in NewConn in tests
90efe21
fix: data race condition
abaa681
fix: don't use dummy adresses in test
aef7b2b
fix: missed nil check
ef50a58
fix: don't upsert if nothing to do
ce20149
fix: prevent against race conditions and dangling pointers
7eb30ba
fix: comment
b175457
fix for golangci-lint
jkralik bec995c
fix(udp): avoid multicast conn key leaks and stale control state
jkralik 2250c27
fix the two gocritic warnings
jkralik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ client | |
| !client/ | ||
| vendor/ | ||
| v3/ | ||
|
|
||
| .idea/ | ||
| # Test binary, build with `go test -c` | ||
| *.test | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "name": "Run simple server", | ||
| "type": "go", | ||
| "request": "launch", | ||
| "mode": "auto", | ||
| "program": "${workspaceFolder}/examples/observe/server" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package client | ||
|
|
||
| import ( | ||
| "net" | ||
| "testing" | ||
|
|
||
| coapNet "github.com/plgd-dev/go-coap/v3/net" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestSetControlInformationNil(t *testing.T) { | ||
| var cc Conn | ||
| addr := net.ParseIP("192.0.2.1").To4() | ||
| cc.localAddr.Store(&addr) | ||
| cc.interfaceIndex.Store(7) | ||
|
|
||
| cc.setControlInformation(nil) | ||
|
|
||
| require.Equal(t, int64(0), cc.interfaceIndex.Load()) | ||
| require.Nil(t, cc.localAddr.Load()) | ||
| } | ||
|
|
||
| func TestSetControlInformationUnicastCopiesAddress(t *testing.T) { | ||
| var cc Conn | ||
| dst := net.ParseIP("2001:db8::1") | ||
| cm := &coapNet.ControlMessage{Dst: append(net.IP(nil), dst...), IfIndex: 9} | ||
|
|
||
| cc.setControlInformation(cm) | ||
|
|
||
| require.Equal(t, int64(9), cc.interfaceIndex.Load()) | ||
| stored := cc.localAddr.Load() | ||
| require.NotNil(t, stored) | ||
| expected := append(net.IP(nil), dst...) | ||
| require.True(t, stored.Equal(expected)) | ||
|
|
||
| cm.Dst[0] ^= 0xff | ||
| require.True(t, stored.Equal(expected)) | ||
| } | ||
|
|
||
| func TestSetControlInformationMulticastClearsAddress(t *testing.T) { | ||
| var cc Conn | ||
| addr := net.ParseIP("192.0.2.1").To4() | ||
| cc.localAddr.Store(&addr) | ||
|
|
||
| cc.setControlInformation(&coapNet.ControlMessage{Dst: net.ParseIP("ff02::1"), IfIndex: 11}) | ||
|
|
||
| require.Equal(t, int64(11), cc.interfaceIndex.Load()) | ||
| require.Nil(t, cc.localAddr.Load()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package server | ||
|
|
||
| import ( | ||
| "net" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestGetConnKeyIgnoresMulticastLocalAddress(t *testing.T) { | ||
| raddr := &net.UDPAddr{IP: net.ParseIP("2001:db8::1"), Port: 56830} | ||
| mcastV6 := &net.UDPAddr{IP: net.ParseIP("ff02::fd"), Port: 5683} | ||
| mcastV4 := &net.UDPAddr{IP: net.ParseIP("224.0.1.187"), Port: 5683} | ||
| normalized := &net.UDPAddr{Port: 5683} | ||
|
|
||
| require.Equal(t, getConnKey(raddr, mcastV6), getConnKey(raddr, normalized)) | ||
| require.Equal(t, getConnKey(raddr, mcastV4), getConnKey(raddr, normalized)) | ||
| } | ||
|
|
||
| func TestGetConnKeyKeepsUnicastLocalAddressDistinct(t *testing.T) { | ||
| raddr := &net.UDPAddr{IP: net.ParseIP("2001:db8::1"), Port: 56830} | ||
| laddrA := &net.UDPAddr{IP: net.ParseIP("2001:db8::10"), Port: 5683} | ||
| laddrB := &net.UDPAddr{IP: net.ParseIP("2001:db8::11"), Port: 5683} | ||
|
|
||
| require.NotEqual(t, getConnKey(raddr, laddrA), getConnKey(raddr, laddrB)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.