diff --git a/lower/nic.go b/lower/nic.go index 676f970..c688bf2 100644 --- a/lower/nic.go +++ b/lower/nic.go @@ -20,6 +20,7 @@ type NIC struct { ifce *water.Interface ip string subnet string + mtu string cidrs []string } @@ -27,7 +28,7 @@ type NIC struct { // 网卡地址为 ip, 所属子网为 subnet // 以本网卡为下一跳的所有子网为 cidrs // cidrs 不包括本网卡 subnet -func NewNIC(ip, subnet string, cidrs ...string) NICIO { +func NewNIC(ip, subnet, mtu string, cidrs ...string) NICIO { ifce, err := water.New(water.Config{DeviceType: water.TUN}) if err != nil { panic(err) @@ -35,8 +36,9 @@ func NewNIC(ip, subnet string, cidrs ...string) NICIO { n := &NIC{ ifce: ifce, ip: ip, - cidrs: cidrs, subnet: subnet, + mtu: mtu, + cidrs: cidrs, } return n } diff --git a/lower/tun_darwin.go b/lower/tun_darwin.go index b1f4649..745d551 100644 --- a/lower/tun_darwin.go +++ b/lower/tun_darwin.go @@ -4,6 +4,7 @@ package lower func (n *NIC) Up() { + execute("ifconfig", n.ifce.Name(), "mtu", n.mtu) execute("ifconfig", n.ifce.Name(), "inet", n.ip, n.ip, "up") execute("route", "add", n.subnet, "-interface", n.ifce.Name()) for _, c := range n.cidrs { diff --git a/lower/tun_linux.go b/lower/tun_linux.go index f77e7ce..6b991ef 100644 --- a/lower/tun_linux.go +++ b/lower/tun_linux.go @@ -4,7 +4,7 @@ package lower func (n *NIC) Up() { - execute("/sbin/ip", "link", "set", "dev", n.ifce.Name(), "mtu", "1500") + execute("/sbin/ip", "link", "set", "dev", n.ifce.Name(), "mtu", n.mtu) execute("/sbin/ip", "addr", "add", n.ip, "dev", n.ifce.Name()) execute("/sbin/ip", "link", "set", "dev", n.ifce.Name(), "up") execute("/sbin/ip", "route", "add", n.subnet, "dev", n.ifce.Name()) diff --git a/lower/tun_windows.go b/lower/tun_windows.go index 514c56f..e676195 100644 --- a/lower/tun_windows.go +++ b/lower/tun_windows.go @@ -11,7 +11,7 @@ func (n *NIC) Up() { if err != nil { panic(err) } - execute("cmd", "/c", "netsh interface ip set address name=\""+n.ifce.Name()+"\" source=static addr=\""+n.ip+"\" mask=\""+(net.IP)(ipn.Mask).String()+"\" gateway=none") + execute("cmd", "/c", "netsh interface ip set address name=\""+n.ifce.Name()+"\" source=static addr=\""+n.ip+"\" mask=\""+(net.IP)(ipn.Mask).String()+"\" gateway=none mtu="+n.mtu) for _, c := range n.cidrs { ip, cidr, err := net.ParseCIDR(c) if err != nil { diff --git a/upper/services/wg/wg.go b/upper/services/wg/wg.go index 28561c1..47625ad 100644 --- a/upper/services/wg/wg.go +++ b/upper/services/wg/wg.go @@ -2,6 +2,7 @@ package wg import ( "errors" + "fmt" "net" base14 "github.com/fumiama/go-base16384" @@ -92,7 +93,7 @@ func (wg *WG) init(srcport, destport, mtu uint16) { &wg.key, wg.c.IP+"/32", wg.c.EndPoint, - lower.NewNIC(wg.c.IP, wg.c.SubNet, cidrs...), + lower.NewNIC(wg.c.IP, wg.c.SubNet, fmt.Sprintf("%d", mtu), cidrs...), srcport, destport, mtu, )