send and track packets with ECN markings

This commit is contained in:
Marten Seemann
2023-08-12 10:08:40 +08:00
parent f919473598
commit 5dd6d91c11
21 changed files with 264 additions and 206 deletions

View File

@@ -9,7 +9,7 @@ import (
// A sendConn allows sending using a simple Write() on a non-connected packet conn.
type sendConn interface {
Write(b []byte, gsoSize uint16) error
Write(b []byte, gsoSize uint16, ecn protocol.ECN) error
Close() error
LocalAddr() net.Addr
RemoteAddr() net.Addr
@@ -43,13 +43,6 @@ func newSendConn(c rawConn, remote net.Addr, info packetInfo, logger utils.Logge
}
oob := info.OOB()
if remoteUDPAddr, ok := remote.(*net.UDPAddr); ok {
if remoteUDPAddr.IP.To4() != nil {
oob = appendIPv4ECNMsg(oob, protocol.ECT1)
} else {
oob = appendIPv6ECNMsg(oob, protocol.ECT1)
}
}
// increase oob slice capacity, so we can add the UDP_SEGMENT and ECN control messages without allocating
l := len(oob)
oob = append(oob, make([]byte, 64)...)[:l]
@@ -62,8 +55,8 @@ func newSendConn(c rawConn, remote net.Addr, info packetInfo, logger utils.Logge
}
}
func (c *sconn) Write(p []byte, gsoSize uint16) error {
_, err := c.WritePacket(p, c.remoteAddr, c.packetInfoOOB, gsoSize)
func (c *sconn) Write(p []byte, gsoSize uint16, ecn protocol.ECN) error {
_, err := c.WritePacket(p, c.remoteAddr, c.packetInfoOOB, gsoSize, ecn)
if err != nil && isGSOError(err) {
// disable GSO for future calls
c.gotGSOError = true
@@ -76,7 +69,7 @@ func (c *sconn) Write(p []byte, gsoSize uint16) error {
if l > int(gsoSize) {
l = int(gsoSize)
}
if _, err := c.WritePacket(p[:l], c.remoteAddr, c.packetInfoOOB, 0); err != nil {
if _, err := c.WritePacket(p[:l], c.remoteAddr, c.packetInfoOOB, 0, ecn); err != nil {
return err
}
p = p[l:]