1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-19 02:46:33 -05:00
v2fly/app/tun/packetaddradaptar.go

42 lines
1.0 KiB
Go
Raw Normal View History

package tun
import (
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/stack"
2023-10-22 20:44:36 -04:00
"github.com/v2fly/v2ray-core/v5/app/tun/device"
"github.com/v2fly/v2ray-core/v5/app/tun/tunsorter"
)
func NewDeviceWithSorter(overlay device.Device, sorter *tunsorter.TunSorter) device.Device {
return &packetAddrDevice{
Device: overlay,
sorter: sorter,
}
}
type packetAddrDevice struct {
device.Device
sorter *tunsorter.TunSorter
secondaryDispatcher stack.NetworkDispatcher
}
func (p *packetAddrDevice) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
buf := pkt.ToBuffer()
_, err := p.sorter.OnPacketReceived(buf.Flatten())
if err != nil {
p.secondaryDispatcher.DeliverNetworkPacket(protocol, pkt)
}
}
func (p *packetAddrDevice) DeliverLinkPacket(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
2023-10-22 20:44:36 -04:00
// TODO implement me
panic("implement me")
}
func (p *packetAddrDevice) Attach(dispatcher stack.NetworkDispatcher) {
p.secondaryDispatcher = dispatcher
p.Device.Attach(p)
}