1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00
v2fly/app/tun/packetaddradaptar.go
2023-10-23 01:47:08 +01:00

42 lines
1.0 KiB
Go

package tun
import (
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/stack"
"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) {
// TODO implement me
panic("implement me")
}
func (p *packetAddrDevice) Attach(dispatcher stack.NetworkDispatcher) {
p.secondaryDispatcher = dispatcher
p.Device.Attach(p)
}