File tree 2 files changed +20
-1
lines changed 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -210,7 +210,6 @@ func main() {
210
210
log .Warn ("Error while setting up the interface TC attributes: " , err )
211
211
return
212
212
}
213
- log .Debugf ("Set %s as the route" , gwaddr )
214
213
215
214
// ============================= Set the default route in the namespace
216
215
Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
+ "fmt"
4
5
"net"
5
6
6
7
"github.com/vishvananda/netlink"
@@ -60,6 +61,25 @@ func newMacVLAN() (*netlink.Link, error) {
60
61
}
61
62
62
63
func setLinkRoute (link * netlink.Link ) error {
64
+ // Add a route for the gateway
65
+ _ , gwaddrNet , err := net .ParseCIDR (fmt .Sprintf ("%s/32" , gwaddr .String ()))
66
+ if err != nil {
67
+ log .Warnf ("Error when parsing gateway" , err )
68
+ return err
69
+ }
70
+ log .Debug ("Setting a route for the gateway" )
71
+ err = netlink .RouteAdd (& netlink.Route {
72
+ Scope : netlink .SCOPE_UNIVERSE ,
73
+ LinkIndex : (* link ).Attrs ().Index ,
74
+ Dst : gwaddrNet ,
75
+ })
76
+ if err != nil {
77
+ log .Warn ("Error while setting link route: " , err )
78
+ return err
79
+ }
80
+
81
+ log .Debugf ("Set %s as the default gateway" , gwaddr )
82
+ // Add the default gateway
63
83
return netlink .RouteAdd (& netlink.Route {
64
84
Scope : netlink .SCOPE_UNIVERSE ,
65
85
LinkIndex : (* link ).Attrs ().Index ,
You can’t perform that action at this time.
0 commit comments