feature: set mtu to tun device

This commit is contained in:
ICKelin
2021-08-13 21:40:27 +08:00
parent 40526d819c
commit 793d71745f
6 changed files with 26 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
language: go
go:
- 1.13
- 1.16
before_install:
- go mod download
install:

View File

@@ -167,7 +167,7 @@ func (s *RegistryServer) onConn(conn net.Conn) {
}()
// reply to edge
conn.SetWriteDeadline(time.Now().Add(time.Second*10))
conn.SetWriteDeadline(time.Now().Add(time.Second * 10))
err = codec.WriteJSON(conn, codec.CmdRegister, &codec.RegisterReply{
EdgeList: otherEdges,
Routes: otherRoutes,
@@ -182,7 +182,7 @@ func (s *RegistryServer) onConn(conn net.Conn) {
fail := 0
hb := codec.Heartbeat{}
for {
conn.SetReadDeadline(time.Now().Add(time.Second*30))
conn.SetReadDeadline(time.Now().Add(time.Second * 30))
header, body, err := codec.Read(conn)
conn.SetReadDeadline(time.Time{})
if err != nil {

View File

@@ -21,7 +21,16 @@ func main() {
}
defer iface.Close()
iface.Up()
err = iface.Up()
if err != nil {
log.Error("up interface fail: %v", err)
return
}
err = iface.SetMTU(1400)
if err != nil {
log.Error("set mtu fail: %v", err)
}
// create cframe udp server
// just hard code listen address once without env var

View File

@@ -37,6 +37,14 @@ func NewInterface() (*Interface, error) {
return nil, fmt.Errorf("new interface %s fail", ifconfig.Name)
}
func (iface *Interface) SetMTU(mtu int) error {
out, err := execCmd("ifconfig", []string{iface.tun.Name(), "mtu", fmt.Sprintf("%d", mtu)})
if err != nil {
return fmt.Errorf("set mtu fail: %s %v", out, err)
}
return nil
}
func (iface *Interface) Up() error {
switch runtime.GOOS {
case "linux":

1
go.mod
View File

@@ -38,6 +38,7 @@ require (
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
github.com/urfave/cli/v2 v2.3.0
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
github.com/xtaci/smux v2.0.1+incompatible
go.etcd.io/bbolt v1.3.3 // indirect
go.uber.org/zap v1.15.0 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect

5
go.sum
View File

@@ -104,8 +104,9 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4 h1:z53tR0945TRRQO/fLEVPI6SMv7ZflF0TEaTAoU7tOzg=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
@@ -216,6 +217,8 @@ github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/X
github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xtaci/smux v2.0.1+incompatible h1:4NrCD5VzuFktMCxK08IShR0C5vKyNICJRShUzvk0U34=
github.com/xtaci/smux v2.0.1+incompatible/go.mod h1:f+nYm6SpuHMy/SH0zpbvAFHT1QoMcgLOsWcFip5KfPw=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/gopher-lua v0.0.0-20171031051903-609c9cd26973/go.mod h1:aEV29XrmTYFr3CiRxZeGHpkvbwq+prZduBqMaascyCU=