@@ -226,40 +226,46 @@ func (oc *ovsController) ensureOvsPort(hostVeth, sandboxID string) (int, error)
226
226
return oc .ovs .AddPort (hostVeth , - 1 , "external-ids=sandbox=" + sandboxID )
227
227
}
228
228
229
- func (oc * ovsController ) setupPodFlows (ofport int , podIP , podMAC string , vnid uint32 ) error {
229
+ func (oc * ovsController ) setupPodFlows (ofport int , podIP net. IP , vnid uint32 ) error {
230
230
otx := oc .ovs .NewTransaction ()
231
231
232
+ ipstr := podIP .String ()
233
+ podIP = podIP .To4 ()
234
+ ipmac := fmt .Sprintf ("00:00:%02x:%02x:%02x:%02x/00:00:ff:ff:ff:ff" , podIP [0 ], podIP [1 ], podIP [2 ], podIP [3 ])
235
+
232
236
// ARP/IP traffic from container
233
- otx .AddFlow ("table=20, priority=100, in_port=%d, arp, nw_src=%s, arp_sha=%s, actions=load:%d->NXM_NX_REG0[], goto_table:21" , ofport , podIP , podMAC , vnid )
234
- otx .AddFlow ("table=20, priority=100, in_port=%d, ip, nw_src=%s, actions=load:%d->NXM_NX_REG0[], goto_table:21" , ofport , podIP , vnid )
237
+ otx .AddFlow ("table=20, priority=100, in_port=%d, arp, nw_src=%s, arp_sha=%s, actions=load:%d->NXM_NX_REG0[], goto_table:21" , ofport , ipstr , ipmac , vnid )
238
+ otx .AddFlow ("table=20, priority=100, in_port=%d, ip, nw_src=%s, actions=load:%d->NXM_NX_REG0[], goto_table:21" , ofport , ipstr , vnid )
235
239
if oc .useConnTrack {
236
- otx .AddFlow ("table=25, priority=100, ip, nw_src=%s, actions=load:%d->NXM_NX_REG0[], goto_table:30" , podIP , vnid )
240
+ otx .AddFlow ("table=25, priority=100, ip, nw_src=%s, actions=load:%d->NXM_NX_REG0[], goto_table:30" , ipstr , vnid )
237
241
}
238
242
239
243
// ARP request/response to container (not isolated)
240
- otx .AddFlow ("table=40, priority=100, arp, nw_dst=%s, actions=output:%d" , podIP , ofport )
244
+ otx .AddFlow ("table=40, priority=100, arp, nw_dst=%s, actions=output:%d" , ipstr , ofport )
241
245
242
246
// IP traffic to container
243
- otx .AddFlow ("table=70, priority=100, ip, nw_dst=%s, actions=load:%d->NXM_NX_REG1[], load:%d->NXM_NX_REG2[], goto_table:80" , podIP , vnid , ofport )
247
+ otx .AddFlow ("table=70, priority=100, ip, nw_dst=%s, actions=load:%d->NXM_NX_REG1[], load:%d->NXM_NX_REG2[], goto_table:80" , ipstr , vnid , ofport )
244
248
245
249
return otx .EndTransaction ()
246
250
}
247
251
248
- func (oc * ovsController ) cleanupPodFlows (podIP string ) error {
252
+ func (oc * ovsController ) cleanupPodFlows (podIP net.IP ) error {
253
+ ipstr := podIP .String ()
254
+
249
255
otx := oc .ovs .NewTransaction ()
250
- otx .DeleteFlows ("ip, nw_dst=%s" , podIP )
251
- otx .DeleteFlows ("ip, nw_src=%s" , podIP )
252
- otx .DeleteFlows ("arp, nw_dst=%s" , podIP )
253
- otx .DeleteFlows ("arp, nw_src=%s" , podIP )
256
+ otx .DeleteFlows ("ip, nw_dst=%s" , ipstr )
257
+ otx .DeleteFlows ("ip, nw_src=%s" , ipstr )
258
+ otx .DeleteFlows ("arp, nw_dst=%s" , ipstr )
259
+ otx .DeleteFlows ("arp, nw_src=%s" , ipstr )
254
260
return otx .EndTransaction ()
255
261
}
256
262
257
- func (oc * ovsController ) SetUpPod (hostVeth , podIP , podMAC , sandboxID string , vnid uint32 ) (int , error ) {
263
+ func (oc * ovsController ) SetUpPod (sandboxID , hostVeth string , podIP net. IP , vnid uint32 ) (int , error ) {
258
264
ofport , err := oc .ensureOvsPort (hostVeth , sandboxID )
259
265
if err != nil {
260
266
return - 1 , err
261
267
}
262
- return ofport , oc .setupPodFlows (ofport , podIP , podMAC , vnid )
268
+ return ofport , oc .setupPodFlows (ofport , podIP , vnid )
263
269
}
264
270
265
271
// Returned list can also be used for port names
@@ -322,64 +328,58 @@ func (oc *ovsController) SetPodBandwidth(hostVeth, sandboxID string, ingressBPS,
322
328
return nil
323
329
}
324
330
325
- func (oc * ovsController ) getPodDetailsBySandboxID (sandboxID string ) (int , string , string , error ) {
331
+ func (oc * ovsController ) getPodDetailsBySandboxID (sandboxID string ) (int , net. IP , error ) {
326
332
strports , err := oc .ovs .Find ("interface" , "ofport" , "external-ids:sandbox=" + sandboxID )
327
333
if err != nil {
328
- return 0 , "" , "" , err
334
+ return 0 , nil , err
329
335
} else if len (strports ) == 0 {
330
- return 0 , "" , "" , fmt .Errorf ("failed to find pod details from OVS flows" )
336
+ return 0 , nil , fmt .Errorf ("failed to find pod details from OVS flows" )
331
337
} else if len (strports ) > 1 {
332
- return 0 , "" , "" , fmt .Errorf ("found multiple ofports for sandbox ID %q: %#v" , sandboxID , strports )
338
+ return 0 , nil , fmt .Errorf ("found multiple ofports for sandbox ID %q: %#v" , sandboxID , strports )
333
339
}
334
340
ofport , err := strconv .Atoi (strports [0 ])
335
341
if err != nil {
336
- return 0 , "" , "" , fmt .Errorf ("could not parse ofport %q: %v" , strports [0 ], err )
342
+ return 0 , nil , fmt .Errorf ("could not parse ofport %q: %v" , strports [0 ], err )
337
343
}
338
344
339
345
flows , err := oc .ovs .DumpFlows ("table=20,arp,in_port=%d" , ofport )
340
346
if err != nil {
341
- return 0 , "" , "" , err
347
+ return 0 , nil , err
342
348
} else if len (flows ) != 1 {
343
- return 0 , "" , "" , fmt .Errorf ("could not find correct OVS flows for port %d" , ofport )
349
+ return 0 , nil , fmt .Errorf ("could not find correct OVS flows for port %d" , ofport )
344
350
}
345
351
346
352
parsed , err := ovs .ParseFlow (ovs .ParseForDump , flows [0 ])
347
353
if err != nil {
348
- return 0 , "" , "" , err
354
+ return 0 , nil , err
349
355
}
350
356
351
- macField , macOk := parsed .FindField ("arp_sha" )
352
357
ipField , ipOk := parsed .FindField ("arp_spa" )
353
- if ! macOk || ! ipOk {
354
- return 0 , "" , "" , fmt .Errorf ("failed to parse OVS flows for sandbox ID %q" , sandboxID )
355
- }
356
-
357
- if _ , err := net .ParseMAC (macField .Value ); err != nil {
358
- return 0 , "" , "" , fmt .Errorf ("failed to parse arp_sha %q: %v" , macField .Value , err )
358
+ if ! ipOk {
359
+ return 0 , nil , fmt .Errorf ("failed to parse OVS flows for sandbox ID %q" , sandboxID )
359
360
}
360
- podMAC := macField . Value
361
- if net . ParseIP ( ipField . Value ) == nil {
362
- return 0 , "" , "" , fmt .Errorf ("failed to parse arp_spa %q" , ipField .Value )
361
+ podIP := net . ParseIP ( ipField . Value )
362
+ if podIP == nil {
363
+ return 0 , nil , fmt .Errorf ("failed to parse arp_spa %q" , ipField .Value )
363
364
}
364
- podIP := ipField .Value
365
365
366
- return ofport , podIP , podMAC , nil
366
+ return ofport , podIP , nil
367
367
}
368
368
369
369
func (oc * ovsController ) UpdatePod (sandboxID string , vnid uint32 ) error {
370
- ofport , podIP , podMAC , err := oc .getPodDetailsBySandboxID (sandboxID )
370
+ ofport , podIP , err := oc .getPodDetailsBySandboxID (sandboxID )
371
371
if err != nil {
372
372
return err
373
373
}
374
374
err = oc .cleanupPodFlows (podIP )
375
375
if err != nil {
376
376
return err
377
377
}
378
- return oc .setupPodFlows (ofport , podIP , podMAC , vnid )
378
+ return oc .setupPodFlows (ofport , podIP , vnid )
379
379
}
380
380
381
381
func (oc * ovsController ) TearDownPod (sandboxID string ) error {
382
- _ , podIP , _ , err := oc .getPodDetailsBySandboxID (sandboxID )
382
+ _ , podIP , err := oc .getPodDetailsBySandboxID (sandboxID )
383
383
if err != nil {
384
384
// OVS flows related to sandboxID not found
385
385
// Nothing needs to be done in that case
0 commit comments