Skip to content

Add option to specify MTU #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}