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