Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
MTU configure
Browse files Browse the repository at this point in the history
  • Loading branch information
lodevil committed Feb 25, 2013
1 parent 93b071a commit cf1f16c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ func (c *Client) nat() error {
if err := tun.SetNetmask(c.nat_info.Netmask); err != nil {
return err
}
if c.nat_info.MTU > 0 {
if err := tun.SetMTU(c.nat_info.MTU); err != nil {
return err
}
}

tun_ch, err := tun.ReadChan()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type NatInfo struct {
IP net.IP
Gateway net.IP
Netmask net.IPMask
MTU int
}

type AuthResult struct {
Expand Down
3 changes: 2 additions & 1 deletion ser.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"nat": {
"net": "192.168.10.0/24",
"gateway": "192.168.10.1"
"gateway": "192.168.10.1",
"mtu": 1500
}
}
29 changes: 29 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Server struct {
cfg map[string]map[string]interface{}
tunnel ServerTunnel
ippool IPPool
mtu int
}

func NewServer(cfg map[string]map[string]interface{}) (ser Server, err error) {
Expand Down Expand Up @@ -53,6 +54,28 @@ func NewServer(cfg map[string]map[string]interface{}) (ser Server, err error) {
if err != nil {
return
}

if imtu, ok := nat_cfg["mtu"]; ok {
switch v := imtu.(type) {
case int:
ser.mtu = v
case int64:
ser.mtu = int(v)
case float32:
ser.mtu = int(v)
case float64:
ser.mtu = int(v)
default:
err = fmt.Errorf("nat.mtu invalid type (int desired)")
return
}
if ser.mtu < 0 {
err = fmt.Errorf("nat.mtu must be a positive int")
return
}
} else {
ser.mtu = 0
}
}

tunnel_cfg, ok := cfg["tunnel"]
Expand Down Expand Up @@ -132,6 +155,7 @@ func (s *Server) auth(cli_ch *ClientChan) (nf NatInfo, err error) {
rst.NatInfo.Gateway = s.ippool.Gateway
rst.NatInfo.Netmask = s.ippool.IPNet.Mask
rst.NatInfo.IP = s.ippool.Next()
rst.NatInfo.MTU = s.mtu
nf = rst.NatInfo
}

Expand All @@ -158,6 +182,11 @@ func (s *Server) nat(cli_ch *ClientChan, nat_info NatInfo) error {
if err := tun.SetNetmask(nat_info.Netmask); err != nil {
return err
}
if s.mtu > 0 {
if err := tun.SetMTU(s.mtu); err != nil {
return err
}
}

tun_ch, err := tun.ReadChan()
if err != nil {
Expand Down

0 comments on commit cf1f16c

Please sign in to comment.