diff --git a/.github/Maria.png b/.github/Maria.png new file mode 100644 index 0000000..118c2ac Binary files /dev/null and b/.github/Maria.png differ diff --git a/.github/rikka.png b/.github/rikka.png deleted file mode 100755 index 419c3eb..0000000 Binary files a/.github/rikka.png and /dev/null differ diff --git a/README.md b/README.md index e9fd2db..56bb4e5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@
- WireGold-Rikka
+ WireGold-Maria

WireGold

Wire Golang Guard = WireGold

diff --git a/config/cfg.go b/config/cfg.go index f57ee20..4a3faf9 100644 --- a/config/cfg.go +++ b/config/cfg.go @@ -28,6 +28,7 @@ type Peer struct { QueryList []string `yaml:"QueryList"` QuerySeconds int64 `yaml:"QuerySeconds"` AllowTrans bool `yaml:"AllowTrans"` + MTU int64 `yaml:"MTU"` } func Parse(path string) (c Config) { diff --git a/gold/link/link.go b/gold/link/link.go index f628094..2269422 100644 --- a/gold/link/link.go +++ b/gold/link/link.go @@ -32,6 +32,8 @@ type Link struct { status int // 是否允许转发 allowtrans bool + // udp 数据包的最大大小 + mtu uint16 } const ( diff --git a/gold/link/me.go b/gold/link/me.go index a1ff0de..271934b 100644 --- a/gold/link/me.go +++ b/gold/link/me.go @@ -88,6 +88,7 @@ func NewMe(cfg *MyConfig) (m Me) { EndPoint: "127.0.0.1:56789", AllowedIPs: []string{cfg.MyIPwithMask}, NoPipe: cfg.NIC != nil, + MTU: cfg.MTU, }) m.srcport = cfg.SrcPort m.dstport = cfg.DstPort diff --git a/gold/link/peer.go b/gold/link/peer.go index 6944a6d..a4caa76 100644 --- a/gold/link/peer.go +++ b/gold/link/peer.go @@ -16,6 +16,7 @@ type PeerConfig struct { AllowedIPs, Querys []string PubicKey *[32]byte KeepAliveDur, QueryTick int64 + MTU uint16 AllowTrans, NoPipe bool } @@ -27,11 +28,15 @@ func (m *Me) AddPeer(cfg *PeerConfig) (l *Link) { if ok { return } + if cfg.MTU == 0 || cfg.MTU == 65535 { + panic("invalid mtu for peer " + cfg.PeerIP) + } l = &Link{ pubk: cfg.PubicKey, peerip: net.ParseIP(cfg.PeerIP), allowtrans: cfg.AllowTrans, me: m, + mtu: uint16(cfg.MTU), } if !cfg.NoPipe { diff --git a/gold/link/send.go b/gold/link/send.go index 3a61598..92637ac 100644 --- a/gold/link/send.go +++ b/gold/link/send.go @@ -12,7 +12,7 @@ import ( // WriteAndPut 向 peer 发包并将包放回缓存池 func (l *Link) WriteAndPut(p *head.Packet, istransfer bool) (n int, err error) { teatype := uint8(rand.Intn(16)) - if len(p.Data) <= int(l.me.mtu) { + if len(p.Data) <= int(l.mtu) { if !istransfer { p.FillHash() p.Data = l.Encode(teatype, p.Data) @@ -30,15 +30,15 @@ func (l *Link) WriteAndPut(p *head.Packet, istransfer bool) (n int, err error) { i := 0 packet := head.SelectPacket() *packet = *p - for ; int(totl)-i > int(l.me.mtu); i += int(l.me.mtu) { - logrus.Debugln("[link] split frag", i, ":", i+int(l.me.mtu), ", remain:", int(totl)-i-int(l.me.mtu)) - packet.Data = data[:int(l.me.mtu)] + for ; int(totl)-i > int(l.mtu); i += int(l.mtu) { + logrus.Debugln("[link] split frag", i, ":", i+int(l.mtu), ", remain:", int(totl)-i-int(l.mtu)) + packet.Data = data[:int(l.mtu)] cnt, err := l.write(packet, teatype, totl, uint16(uint(i)>>3), istransfer, true) n += cnt if err != nil { return n, err } - data = data[int(l.me.mtu):] + data = data[int(l.mtu):] packet.TTL = ttl } packet.Put() @@ -54,7 +54,7 @@ func (l *Link) write(p *head.Packet, teatype uint8, datasz uint32, offset uint16 var d []byte var cl func() if istransfer { - if p.Flags&0x4000 == 0x4000 && len(p.Data) > int(l.me.mtu) { + if p.Flags&0x4000 == 0x4000 && len(p.Data) > int(l.mtu) { return len(p.Data), errors.New("drop dont fragmnet big trans packet") } d, cl = p.Marshal(nil, teatype, 0, 0, false, false) diff --git a/upper/services/tunnel/tunnel_test.go b/upper/services/tunnel/tunnel_test.go index 9721aad..1923f69 100644 --- a/upper/services/tunnel/tunnel_test.go +++ b/upper/services/tunnel/tunnel_test.go @@ -41,6 +41,7 @@ func TestTunnel(t *testing.T) { EndPoint: "127.0.0.1:1237", AllowedIPs: []string{"192.168.1.3/32"}, PubicKey: peerpk.Public(), + MTU: 4096, }) p := link.NewMe(&link.MyConfig{ MyIPwithMask: "192.168.1.3/32", @@ -55,6 +56,7 @@ func TestTunnel(t *testing.T) { EndPoint: "127.0.0.1:1236", AllowedIPs: []string{"192.168.1.2/32"}, PubicKey: selfpk.Public(), + MTU: 4096, }) tunnme, err := Create(&m, "192.168.1.3") if err != nil { diff --git a/upper/services/wg/wg.go b/upper/services/wg/wg.go index 19407c8..173a826 100644 --- a/upper/services/wg/wg.go +++ b/upper/services/wg/wg.go @@ -117,6 +117,7 @@ func (wg *WG) init(srcport, dstport, mtu uint16) { PubicKey: &peerkey, KeepAliveDur: peer.KeepAliveSeconds, QueryTick: peer.QuerySeconds, + MTU: uint16(peer.MTU), AllowTrans: peer.AllowTrans, NoPipe: true, })