TUN-5659: Proxy UDP with zero-byte payload

This commit is contained in:
cthuang
2022-01-19 18:24:16 +00:00
committed by Chung Ting Huang
parent 10fc450ae5
commit c196679bc7
2 changed files with 42 additions and 0 deletions

View File

@@ -106,6 +106,7 @@ func (s *Session) waitForCloseCondition(ctx context.Context, closeAfterIdle time
func (s *Session) dstToTransport(buffer []byte) error {
n, err := s.dstConn.Read(buffer)
s.markActive()
// https://pkg.go.dev/io#Reader suggests caller should always process n > 0 bytes
if n > 0 {
if n <= int(s.transport.MTU()) {
err = s.transport.SendTo(s.ID, buffer[:n])
@@ -118,6 +119,10 @@ func (s *Session) dstToTransport(buffer []byte) error {
Msg("dropped packet exceeding MTU")
}
}
// Some UDP application might send 0-size payload.
if err == nil && n == 0 {
err = s.transport.SendTo(s.ID, []byte{})
}
return err
}