mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-05 07:50:24 +08:00
add mtu
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user