From 3443d3ffd38cd7e611513b644ea15b144e28a079 Mon Sep 17 00:00:00 2001 From: JackDoan Date: Fri, 14 Nov 2025 11:38:34 -0600 Subject: [PATCH] correctly set ethertype, at least for single-IP networks --- overlay/tun_linux.go | 8 ++++++-- packet/outpacket.go | 11 ++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/overlay/tun_linux.go b/overlay/tun_linux.go index 86e36e9..4108aad 100644 --- a/overlay/tun_linux.go +++ b/overlay/tun_linux.go @@ -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 } diff --git a/packet/outpacket.go b/packet/outpacket.go index 42dd5dd..3ae13bb 100644 --- a/packet/outpacket.go +++ b/packet/outpacket.go @@ -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:])