1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-04 23:40:26 +08:00

drop commandline mtu

This commit is contained in:
源文雨
2022-05-13 23:13:30 +08:00
parent 4e833c877d
commit 52215ec63a
4 changed files with 18 additions and 16 deletions

View File

@@ -7,7 +7,7 @@
## Usage
> If you are running in windows, remember to select the `wintun.dll` of your arch in `lower/wintun` and place it alongside the compiled exe
```bash
wg [-c config.yaml] [-d|w] [-g] [-h] [-m mtu] [-p] [-l log.txt]
wg [-c config.yaml] [-d|w] [-g] [-h] [-p] [-l log.txt]
```
#### Instructions
```bash
@@ -18,21 +18,21 @@ wg [-c config.yaml] [-d|w] [-g] [-h] [-m mtu] [-p] [-l log.txt]
-h display this help
-l string
write log to file (default "-")
-m int
set the mtu of wg (default 1432)
-p show my publickey
-w only show logs above warn level
```
- **macos mojave**: max mtu (under ipv4 endpoint) is `9159`
- **ipv6 endpoint**: the recommand mtu is `1280~1400` to prevent the big segments from being dropped
## Config file example
- **macos mojave**: max mtu (under ipv4 endpoint) is `9159`
- **ipv6 endpoint**: the recommand mtu is `1280~1500` to prevent the big segments from being dropped
```yaml
IP: 192.168.233.1
SubNet: 192.168.233.0/24
PrivateKey: 暲菉斂狧污爉窫擸紈卆帞蔩慈睠庮扝憚瞼縀
EndPoint: 0.0.0.0:56789
MTU: 1500
Peers:
-
IP: "192.168.233.2"
@@ -42,6 +42,7 @@ Peers:
AllowedIPs: ["192.168.233.2/32"]
KeepAliveSeconds: 0
QueryList: ["192.168.233.3"]
MTU: 1400
QuerySeconds: 10
AllowTrans: false
-
@@ -50,6 +51,7 @@ Peers:
PublicKey: 牢喨粷詸衭譛浾蘹櫠砙杹蟫瑳叩刋橋経挵蘀
EndPoint: ""
AllowedIPs: ["192.168.233.3/32"]
MTU: 1300
KeepAliveSeconds: 0
AllowTrans: false
```

View File

@@ -14,6 +14,7 @@ type Config struct {
SubNet string `yaml:"SubNet"`
PrivateKey string `yaml:"PrivateKey"`
EndPoint string `yaml:"EndPoint"`
MTU int64 `yaml:"MTU"`
Peers []Peer `yaml:"Peers"`
}

View File

@@ -21,7 +21,6 @@ func main() {
gen := flag.Bool("g", false, "generate key pair")
showp := flag.Bool("p", false, "show my publickey")
file := flag.String("c", "config.yaml", "specify conf file")
mtu := flag.Int("m", 1500-68, "set the mtu of wg")
debug := flag.Bool("d", false, "print debug logs")
warn := flag.Bool("w", false, "only show logs above warn level")
logfile := flag.String("l", "-", "write log to file")
@@ -129,7 +128,7 @@ func main() {
}
defer w.Stop()
w.Run(upper.ServiceWireGold, upper.ServiceWireGold, uint16(*mtu))
w.Run(upper.ServiceWireGold, upper.ServiceWireGold)
}
func displayHelp(hint string) {

View File

@@ -2,8 +2,8 @@ package wg
import (
"errors"
"fmt"
"net"
"strconv"
base14 "github.com/fumiama/go-base16384"
curve "github.com/fumiama/go-x25519"
@@ -48,13 +48,13 @@ func NewWireGold(c *config.Config) (wg WG, err error) {
return
}
func (wg *WG) Start(srcport, destport, mtu uint16) {
wg.init(srcport, destport, mtu)
func (wg *WG) Start(srcport, destport uint16) {
wg.init(srcport, destport)
go wg.me.ListenFromNIC()
}
func (wg *WG) Run(srcport, destport, mtu uint16) {
wg.init(srcport, destport, mtu)
func (wg *WG) Run(srcport, destport uint16) {
wg.init(srcport, destport)
_, err := wg.me.ListenFromNIC()
if err != nil {
logrus.Panicln(err)
@@ -65,7 +65,7 @@ func (wg *WG) Stop() {
_ = wg.me.Close()
}
func (wg *WG) init(srcport, dstport, mtu uint16) {
func (wg *WG) init(srcport, dstport uint16) {
cidrsmap := make(map[string]bool, 32)
_, mysubnet, err := net.ParseCIDR(wg.c.SubNet)
if err != nil {
@@ -93,10 +93,10 @@ func (wg *WG) init(srcport, dstport, mtu uint16) {
MyIPwithMask: wg.c.IP + "/32",
MyEndpoint: wg.c.EndPoint,
PrivateKey: &wg.key,
NIC: lower.NewNIC(wg.c.IP, wg.c.SubNet, fmt.Sprintf("%d", mtu), cidrs...),
NIC: lower.NewNIC(wg.c.IP, wg.c.SubNet, strconv.FormatInt(wg.c.MTU, 64), cidrs...),
SrcPort: srcport,
DstPort: dstport,
MTU: mtu,
MTU: uint16(wg.c.MTU),
})
for _, peer := range wg.c.Peers {