Skip to content

Commit e82ce79

Browse files
authored
Merge pull request #16 from PouuleT/mtu
Add option to specify MTU
2 parents 64b1a83 + ae90fdc commit e82ce79

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
loss added on the interface in percentage (default 0)
2727
-jitter uint
2828
jitter added on the interface in ms (default 0)
29+
-mtu int
30+
MTU of the interface
2931
-latency uint
3032
latency added on the interface in ms (default 0)
3133
```

main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
var ip, command, gateway, intf, logLevel, nsPath, mac string
1818
var latency, jitter uint
19+
var mtu int
1920
var loss float64
2021
var log = logrus.New()
2122
var namespace, origns *netns.NsHandle
@@ -37,6 +38,7 @@ func init() {
3738
flag.UintVar(&latency, "latency", 0, "latency added on the interface in ms")
3839
flag.UintVar(&jitter, "jitter", 0, "jitter added on the interface in ms")
3940
flag.Float64Var(&loss, "loss", 0, "loss added on the interface in percentage")
41+
flag.IntVar(&mtu, "mtu", 0, "MTU of the interface")
4042
flag.StringVar(
4143
&nsPath,
4244
"ns-path",
@@ -148,6 +150,14 @@ func main() {
148150
return
149151
}
150152

153+
// ============================= Set the mtu of the macVlan interface
154+
155+
err = setMacVlanMTU(link)
156+
if err != nil {
157+
log.Warn("Error while setting vlan MTU: ", err)
158+
return
159+
}
160+
151161
// ============================== Create the new Namespace
152162

153163
namespace, err = newNS()

net.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,17 @@ func setMacVlanMacAddr(link *netlink.Link) error {
105105
}
106106
return nil
107107
}
108+
109+
func setMacVlanMTU(link *netlink.Link) error {
110+
// If a mtu was specified, set it now
111+
if mtu == 0 {
112+
return nil
113+
}
114+
log.Debugf("Setting macVlan with specified MTU : %s", mtu)
115+
err = netlink.LinkSetMTU(*link, mtu)
116+
if err != nil {
117+
log.Warn("Error while setting given mtu on macVlan: ", err)
118+
return err
119+
}
120+
return nil
121+
}

0 commit comments

Comments
 (0)