Missing effectiveNetProtos means that such endpoint won't be closed correctly: while stack.RegisterTransportEndpoint is called with hardcoded netProtos in ForwarderRequest.CreateEndpoints, the UnregisterTransportEndpoint in endpoint.Close is called with netprotos == nil.
This means that the code as simple as
...
var wq waiter.Queue
f := udp.NewForwarder(s, func(r *udp.ForwarderRequest) {
if zalupa, err := r.CreateEndpoint(&wq); err == nil {
log.Printf("Packet received: %v", r.ID())
zalupa.Close()
}
})
s.SetTransportProtocolHandler(udp.ProtocolNumber, f.HandlePacket)
...
The endpoint returned by
udp.ForwarderRequest.CreateEndpoint
doesn't haveeffectiveNetProtos
filled (it'snil
).Maybe I'm missing something and I should do some initialization by hand?
There're two things that make me think this is not true:
tcp.ForwarderRequest.CreateEndpoint
have theireffectiveNetProtos
set.udp.Forwarder
at https://github.com/google/gvisor/blob/master/pkg/tcpip/adapters/gonet/gonet_test.go#L354 doesn't do anything more thanCreateEndpoint
.Missing
effectiveNetProtos
means that such endpoint won't be closed correctly: whilestack.RegisterTransportEndpoint
is called with hardcodednetProtos
inForwarderRequest.CreateEndpoints
, theUnregisterTransportEndpoint
inendpoint.Close
is called withnetprotos == nil
.This means that the code as simple as
misses new packets if the source port is reused.