correctly set ethertype, at least for single-IP networks

This commit is contained in:
JackDoan
2025-11-14 11:38:34 -06:00
parent a39d3c79b2
commit 3443d3ffd3
2 changed files with 14 additions and 5 deletions

View File

@@ -43,7 +43,8 @@ type tun struct {
useSystemRoutes bool
useSystemRoutesBufferSize int
l *logrus.Logger
isV6 bool
l *logrus.Logger
}
func (t *tun) Networks() []netip.Prefix {
@@ -163,6 +164,9 @@ func newTunGeneric(c *config.C, l *logrus.Logger, file *os.File, vpnNetworks []n
useSystemRoutesBufferSize: c.GetInt("tun.use_system_route_table_buffer_size", 0),
l: l,
}
if len(vpnNetworks) != 0 {
t.isV6 = vpnNetworks[0].Addr().Is6() //todo what about multi-IP?
}
err := t.reload(c, true)
if err != nil {
@@ -738,7 +742,7 @@ func (t *tun) AllocSeg(pkt *packet.OutPacket, q int) (int, error) {
if err != nil {
return 0, err
}
x := pkt.UseSegment(idx, buf)
x := pkt.UseSegment(idx, buf, t.isV6)
return x, nil
}

View File

@@ -39,7 +39,7 @@ func (pkt *OutPacket) Reset() {
pkt.wasSegmented = false
}
func (pkt *OutPacket) UseSegment(segID uint16, seg []byte) int {
func (pkt *OutPacket) UseSegment(segID uint16, seg []byte, isV6 bool) int {
pkt.Valid = true
pkt.SegmentIDs = append(pkt.SegmentIDs, segID)
pkt.Segments = append(pkt.Segments, seg) //todo do we need this?
@@ -56,8 +56,13 @@ func (pkt *OutPacket) UseSegment(segID uint16, seg []byte) int {
hdr := seg[0 : virtio.NetHdrSize+14]
_ = vhdr.Encode(hdr)
hdr[virtio.NetHdrSize+14-2] = 0x86
hdr[virtio.NetHdrSize+14-1] = 0xdd //todo ipv6 ethertype
if isV6 {
hdr[virtio.NetHdrSize+14-2] = 0x86
hdr[virtio.NetHdrSize+14-1] = 0xdd
} else {
hdr[virtio.NetHdrSize+14-2] = 0x08
hdr[virtio.NetHdrSize+14-1] = 0x00
}
pkt.SegmentHeaders = append(pkt.SegmentHeaders, hdr)
pkt.SegmentPayloads = append(pkt.SegmentPayloads, seg[virtio.NetHdrSize+14:])