@@ -17,7 +17,7 @@ import (
17
17
"github.com/vishvananda/netns"
18
18
)
19
19
20
- var ip , command , gateway , intf , logLevel , nsPath string
20
+ var ip , command , gateway , intf , logLevel , nsPath , mac string
21
21
var log = logrus .New ()
22
22
23
23
func init () {
@@ -26,6 +26,7 @@ func init() {
26
26
flag .StringVar (& command , "command" , "ip route" , "command to be executed" )
27
27
flag .StringVar (& gateway , "gw" , "" , "gateway of the request (default will be the default route of the given interface)" )
28
28
flag .StringVar (& logLevel , "log-level" , "info" , "min level of logs to print" )
29
+ flag .StringVar (& mac , "mac" , "" , "mac address of the interface inside the namespace (default will be a random one)" )
29
30
flag .StringVar (
30
31
& nsPath ,
31
32
"ns-path" ,
@@ -120,19 +121,28 @@ func main() {
120
121
return
121
122
}
122
123
123
- err = netlink .LinkSetDown (macVlan )
124
- if err != nil {
125
- log .Warn ("Error while setting macVlan down: " , err )
126
- return
127
- }
128
-
129
124
link , err := netlink .LinkByName ("peth0" )
130
125
if err != nil {
131
126
log .Warn ("Error while getting macVlan: " , err )
132
127
return
133
128
}
134
129
log .Debugf ("MacVlan created : %+v" , link )
135
130
131
+ // If a mac was specified, set it now
132
+ if mac != "" {
133
+ log .Debugf ("Setting macVlan with specified MAC : %s" , mac )
134
+ hardwareAddr , err := net .ParseMAC (mac )
135
+ if err != nil {
136
+ log .Warn ("Error while parsing given mac: " , err )
137
+ return
138
+ }
139
+ err = netlink .LinkSetHardwareAddr (link , hardwareAddr )
140
+ if err != nil {
141
+ log .Warn ("Error while setting given mac on macVlan: " , err )
142
+ return
143
+ }
144
+ }
145
+
136
146
// ============================== Create the new Namespace
137
147
138
148
newns , err := newNS ()
0 commit comments