Skip to content
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

Initialize source port and destination port if possible #312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Initialize source and dest port if possible
if association is initialized with a net.Conn take the ports from there
hugoArregui committed Mar 1, 2024
commit 90d37b4778a1fc4a5669d2cec9bc54e4d135f31a
22 changes: 20 additions & 2 deletions association.go
Original file line number Diff line number Diff line change
@@ -101,6 +101,16 @@
acceptChSize = 16
)

func getPort(addr net.Addr) uint16 {
switch addr := addr.(type) {
case *net.UDPAddr:
return uint16(addr.Port)
case *net.TCPAddr:
return uint16(addr.Port)

Check warning on line 109 in association.go

Codecov / codecov/patch

association.go#L108-L109

Added lines #L108 - L109 were not covered by tests
}
return 0
}

func getAssociationStateString(a uint32) string {
switch a {
case closed:
@@ -337,6 +347,10 @@
log: config.LoggerFactory.NewLogger("sctp"),
}

if config.NetConn != nil {
a.sourcePort = getPort(config.NetConn.LocalAddr())
a.destinationPort = getPort(config.NetConn.RemoteAddr())
}
a.name = fmt.Sprintf("%p", a)

// RFC 4690 Sec 7.2.1
@@ -399,8 +413,12 @@

outbound := &packet{}
outbound.verificationTag = a.peerVerificationTag
a.sourcePort = defaultSCTPSrcDstPort
a.destinationPort = defaultSCTPSrcDstPort
if a.sourcePort == 0 {
a.sourcePort = defaultSCTPSrcDstPort
}
if a.destinationPort == 0 {
a.destinationPort = defaultSCTPSrcDstPort
}
outbound.sourcePort = a.sourcePort
outbound.destinationPort = a.destinationPort


Unchanged files with check annotations Beta

gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)
go 1.13

Check failure on line 12 in go.mod

GitHub Actions / lint / Metadata

Invalid Go version

Found 1.13. Expected 1.19