Skip to content

Commit

Permalink
Add option to specify MTU
Browse files Browse the repository at this point in the history
  • Loading branch information
PouuleT committed Nov 5, 2016
1 parent 64b1a83 commit ae90fdc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
loss added on the interface in percentage (default 0)
-jitter uint
jitter added on the interface in ms (default 0)
-mtu int
MTU of the interface
-latency uint
latency added on the interface in ms (default 0)
```
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

var ip, command, gateway, intf, logLevel, nsPath, mac string
var latency, jitter uint
var mtu int
var loss float64
var log = logrus.New()
var namespace, origns *netns.NsHandle
Expand All @@ -37,6 +38,7 @@ func init() {
flag.UintVar(&latency, "latency", 0, "latency added on the interface in ms")
flag.UintVar(&jitter, "jitter", 0, "jitter added on the interface in ms")
flag.Float64Var(&loss, "loss", 0, "loss added on the interface in percentage")
flag.IntVar(&mtu, "mtu", 0, "MTU of the interface")
flag.StringVar(
&nsPath,
"ns-path",
Expand Down Expand Up @@ -148,6 +150,14 @@ func main() {
return
}

// ============================= Set the mtu of the macVlan interface

err = setMacVlanMTU(link)
if err != nil {
log.Warn("Error while setting vlan MTU: ", err)
return
}

// ============================== Create the new Namespace

namespace, err = newNS()
Expand Down
14 changes: 14 additions & 0 deletions net.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,17 @@ func setMacVlanMacAddr(link *netlink.Link) error {
}
return nil
}

func setMacVlanMTU(link *netlink.Link) error {
// If a mtu was specified, set it now
if mtu == 0 {
return nil
}
log.Debugf("Setting macVlan with specified MTU : %s", mtu)
err = netlink.LinkSetMTU(*link, mtu)
if err != nil {
log.Warn("Error while setting given mtu on macVlan: ", err)
return err
}
return nil
}

0 comments on commit ae90fdc

Please sign in to comment.