@@ -142,26 +142,30 @@ func addIpToLink(ip string, iface netlink.Link) error {
142
142
143
143
func addIpRoutes (ep * danmtypes.DanmEp , dnet * danmtypes.DanmNet ) error {
144
144
defaultRoutingTable := 0
145
- err := addRoutes (dnet .Spec .Options .Routes , ep .Spec .Iface .Address , defaultRoutingTable )
145
+ link , err := netlink .LinkByName (ep .Spec .Iface .Name )
146
+ if err != nil {
147
+ return errors .New ("cannot find Pod interface: " + ep .Spec .Iface .Name + " for adding IP route because:" + err .Error ())
148
+ }
149
+ err = addRouteForLink (dnet .Spec .Options .Routes , ep .Spec .Iface .Address , defaultRoutingTable , link )
146
150
if err != nil {
147
151
return err
148
152
}
149
- err = addRoutes (dnet .Spec .Options .Routes6 , ep .Spec .Iface .AddressIPv6 , defaultRoutingTable )
153
+ err = addRouteForLink (dnet .Spec .Options .Routes6 , ep .Spec .Iface .AddressIPv6 , defaultRoutingTable , link )
150
154
if err != nil {
151
155
return err
152
156
}
153
- err = addPolicyRoute (dnet .Spec .Options .RTables , ep .Spec .Iface .Address , ep .Spec .Iface .Proutes )
157
+ err = addPolicyRouteForLink (dnet .Spec .Options .RTables , ep .Spec .Iface .Address , ep .Spec .Iface .Proutes , link )
154
158
if err != nil {
155
159
return err
156
160
}
157
- err = addPolicyRoute (dnet .Spec .Options .RTables , ep .Spec .Iface .AddressIPv6 , ep .Spec .Iface .Proutes6 )
161
+ err = addPolicyRouteForLink (dnet .Spec .Options .RTables , ep .Spec .Iface .AddressIPv6 , ep .Spec .Iface .Proutes6 , link )
158
162
if err != nil {
159
163
return err
160
164
}
161
165
return nil
162
166
}
163
167
164
- func addRoutes (routes map [string ]string , allocatedIp string , rtable int ) error {
168
+ func addRouteForLink (routes map [string ]string , allocatedIp string , rtable int , link netlink. Link ) error {
165
169
if routes == nil || allocatedIp == "" || allocatedIp == ipam .NoneAllocType {
166
170
return nil
167
171
}
@@ -176,7 +180,8 @@ func addRoutes(routes map[string]string, allocatedIp string, rtable int) error {
176
180
//Bad gateway in IP route, ignoring the route
177
181
continue
178
182
}
179
- route := netlink.Route {
183
+ route := netlink.Route {
184
+ LinkIndex : link .Attrs ().Index ,
180
185
Dst : ipnet ,
181
186
Gw : ip ,
182
187
}
@@ -193,7 +198,7 @@ func addRoutes(routes map[string]string, allocatedIp string, rtable int) error {
193
198
return nil
194
199
}
195
200
196
- func addPolicyRoute (rtable int , cidr string , proutes map [string ]string ) error {
201
+ func addPolicyRouteForLink (rtable int , cidr string , proutes map [string ]string , link netlink. Link ) error {
197
202
if rtable == 0 || cidr == "" || cidr == ipam .NoneAllocType || proutes == nil {
198
203
return nil
199
204
}
@@ -206,7 +211,7 @@ func addPolicyRoute(rtable int, cidr string, proutes map[string]string) error {
206
211
if err != nil {
207
212
return errors .New ("cannot add rule for policy-based IP routes because:" + err .Error ())
208
213
}
209
- err = addRoutes (proutes , cidr , rtable )
214
+ err = addRouteForLink (proutes , cidr , rtable , link )
210
215
if err != nil {
211
216
return err
212
217
}
0 commit comments