@@ -81,7 +81,7 @@ func (plugin *BFDConfigurator) Init(logger logging.PluginLogger, goVppMux govppm
81
81
}
82
82
83
83
// VPP API handler
84
- if plugin .bfdHandler , err = vppcalls .NewBfdVppHandler (plugin .vppChan , plugin .log , plugin .stopwatch ); err != nil {
84
+ if plugin .bfdHandler , err = vppcalls .NewBfdVppHandler (plugin .vppChan , plugin .ifIndexes , plugin . log , plugin .stopwatch ); err != nil {
85
85
return err
86
86
}
87
87
@@ -244,45 +244,6 @@ func (plugin *BFDConfigurator) DeleteBfdSession(bfdInput *bfd.SingleHopBFD_Sessi
244
244
return nil
245
245
}
246
246
247
- // DumpBfdSessions returns a list of all configured BFD sessions
248
- func (plugin * BFDConfigurator ) DumpBfdSessions () ([]* bfd.SingleHopBFD_Session , error ) {
249
- var bfdSessionList []* bfd.SingleHopBFD_Session
250
-
251
- bfdList , err := plugin .bfdHandler .DumpBfdUDPSessions ()
252
- if err != nil {
253
- return bfdSessionList , err
254
- }
255
-
256
- var wasError error
257
- for _ , bfdItem := range bfdList {
258
- // find interface
259
- ifName , _ , found := plugin .ifIndexes .LookupName (bfdItem .SwIfIndex )
260
- if ! found {
261
- plugin .log .Warnf ("required interface %v not found for BFD" , bfdItem .SwIfIndex )
262
- }
263
-
264
- // Prepare IPv4 IP addresses
265
- var dstAddr net.IP = bfdItem .PeerAddr [:4 ]
266
- var srcAddr net.IP = bfdItem .LocalAddr [:4 ]
267
-
268
- bfdSessionList = append (bfdSessionList , & bfd.SingleHopBFD_Session {
269
- Interface : ifName ,
270
- DestinationAddress : dstAddr .To4 ().String (),
271
- SourceAddress : srcAddr .To4 ().String (),
272
- Enabled : true ,
273
- DesiredMinTxInterval : bfdItem .DesiredMinTx ,
274
- RequiredMinRxInterval : bfdItem .RequiredMinRx ,
275
- DetectMultiplier : uint32 (bfdItem .DetectMult ),
276
- Authentication : & bfd.SingleHopBFD_Session_Authentication {
277
- KeyId : uint32 (bfdItem .BfdKeyID ),
278
- AdvertisedKeyId : uint32 (bfdItem .BfdKeyID ),
279
- },
280
- })
281
- }
282
-
283
- return bfdSessionList , wasError
284
- }
285
-
286
247
// ConfigureBfdAuthKey crates new authentication key which can be used for BFD session
287
248
func (plugin * BFDConfigurator ) ConfigureBfdAuthKey (bfdAuthKey * bfd.SingleHopBFD_Key ) error {
288
249
plugin .log .Infof ("Configuring BFD authentication key with ID %v" , bfdAuthKey .Id )
@@ -311,17 +272,21 @@ func (plugin *BFDConfigurator) ModifyBfdAuthKey(oldInput *bfd.SingleHopBFD_Key,
311
272
if err != nil {
312
273
return fmt .Errorf ("error while verifying authentication key usage. Id: %d: %v" , oldInput .Id , err )
313
274
}
314
- if len (sessionList ) != 0 {
275
+ if sessionList != nil && len (sessionList . Session ) != 0 {
315
276
// Authentication Key is used and cannot be removed directly
316
- for _ , bfds := range sessionList {
317
- sourceAddr := net .HardwareAddr (bfds .LocalAddr ).String ()
318
- destAddr := net .HardwareAddr (bfds .PeerAddr ).String ()
319
- err := plugin .bfdHandler .DeleteBfdUDPSession (bfds .SwIfIndex , sourceAddr , destAddr )
277
+ for _ , bfds := range sessionList .Session {
278
+ sourceAddr := net .HardwareAddr (bfds .SourceAddress ).String ()
279
+ destAddr := net .HardwareAddr (bfds .DestinationAddress ).String ()
280
+ ifIdx , _ , found := plugin .ifIndexes .LookupIdx (bfds .Interface )
281
+ if ! found {
282
+ plugin .log .Warnf ("Modify BFD auth key: interface index for %s not found" , bfds .Interface )
283
+ }
284
+ err := plugin .bfdHandler .DeleteBfdUDPSession (ifIdx , sourceAddr , destAddr )
320
285
if err != nil {
321
286
return err
322
287
}
323
288
}
324
- plugin .log .Debugf ("%v session(s) temporary removed" , len (sessionList ))
289
+ plugin .log .Debugf ("%v session(s) temporary removed" , len (sessionList . Session ))
325
290
}
326
291
327
292
err = plugin .bfdHandler .DeleteBfdUDPAuthenticationKey (oldInput )
@@ -334,14 +299,18 @@ func (plugin *BFDConfigurator) ModifyBfdAuthKey(oldInput *bfd.SingleHopBFD_Key,
334
299
}
335
300
336
301
// Recreate BFD sessions if necessary
337
- if len (sessionList ) != 0 {
338
- for _ , bfdSession := range sessionList {
339
- err := plugin .bfdHandler .AddBfdUDPSessionFromDetails (bfdSession , plugin .keysIndexes )
302
+ if sessionList != nil && len (sessionList .Session ) != 0 {
303
+ for _ , bfdSession := range sessionList .Session {
304
+ ifIdx , _ , found := plugin .ifIndexes .LookupIdx (bfdSession .Interface )
305
+ if ! found {
306
+ plugin .log .Warnf ("Modify BFD auth key: interface index for %s not found" , bfdSession .Interface )
307
+ }
308
+ err := plugin .bfdHandler .AddBfdUDPSession (bfdSession , ifIdx , plugin .keysIndexes )
340
309
if err != nil {
341
310
return err
342
311
}
343
312
}
344
- plugin .log .Debugf ("%v session(s) recreated" , len (sessionList ))
313
+ plugin .log .Debugf ("%v session(s) recreated" , len (sessionList . Session ))
345
314
}
346
315
347
316
return nil
@@ -357,17 +326,19 @@ func (plugin *BFDConfigurator) DeleteBfdAuthKey(bfdInput *bfd.SingleHopBFD_Key)
357
326
return fmt .Errorf ("error while verifying authentication key usage. Id: %v" , bfdInput .Id )
358
327
}
359
328
360
- if len (sessionList ) != 0 {
329
+ if sessionList != nil && len (sessionList . Session ) != 0 {
361
330
// Authentication Key is used and cannot be removed directly
362
- for _ , bfds := range sessionList {
363
- sourceAddr := net .IP (bfds .LocalAddr [0 :4 ]).String ()
364
- destAddr := net .IP (bfds .PeerAddr [0 :4 ]).String ()
365
- err := plugin .bfdHandler .DeleteBfdUDPSession (bfds .SwIfIndex , sourceAddr , destAddr )
331
+ for _ , bfds := range sessionList .Session {
332
+ ifIdx , _ , found := plugin .ifIndexes .LookupIdx (bfds .Interface )
333
+ if ! found {
334
+ plugin .log .Warnf ("Delete BFD auth key: interface index for %s not found" , bfds .Interface )
335
+ }
336
+ err := plugin .bfdHandler .DeleteBfdUDPSession (ifIdx , bfds .SourceAddress , bfds .DestinationAddress )
366
337
if err != nil {
367
338
return err
368
339
}
369
340
}
370
- plugin .log .Debugf ("%v session(s) temporary removed" , len (sessionList ))
341
+ plugin .log .Debugf ("%v session(s) temporary removed" , len (sessionList . Session ))
371
342
}
372
343
err = plugin .bfdHandler .DeleteBfdUDPAuthenticationKey (bfdInput )
373
344
if err != nil {
@@ -377,46 +348,22 @@ func (plugin *BFDConfigurator) DeleteBfdAuthKey(bfdInput *bfd.SingleHopBFD_Key)
377
348
plugin .keysIndexes .UnregisterName (authKeyIDAsString )
378
349
plugin .log .Debugf ("BFD authentication key with id %v unregistered" , bfdInput .Id )
379
350
// Recreate BFD sessions if necessary
380
- if len (sessionList ) != 0 {
381
- for _ , bfdSession := range sessionList {
382
- err := plugin .bfdHandler .AddBfdUDPSessionFromDetails (bfdSession , plugin .keysIndexes )
351
+ if sessionList != nil && len (sessionList .Session ) != 0 {
352
+ for _ , bfdSession := range sessionList .Session {
353
+ ifIdx , _ , found := plugin .ifIndexes .LookupIdx (bfdSession .Interface )
354
+ if ! found {
355
+ plugin .log .Warnf ("Delete BFD auth key: interface index for %s not found" , bfdSession .Interface )
356
+ }
357
+ err := plugin .bfdHandler .AddBfdUDPSession (bfdSession , ifIdx , plugin .keysIndexes )
383
358
if err != nil {
384
359
return err
385
360
}
386
361
}
387
- plugin .log .Debugf ("%v session(s) recreated" , len (sessionList ))
362
+ plugin .log .Debugf ("%v session(s) recreated" , len (sessionList . Session ))
388
363
}
389
364
return nil
390
365
}
391
366
392
- // DumpBFDAuthKeys returns a list of all configured authentication keys
393
- func (plugin * BFDConfigurator ) DumpBFDAuthKeys () ([]* bfd.SingleHopBFD_Key , error ) {
394
- var bfdAuthKeyList []* bfd.SingleHopBFD_Key
395
-
396
- keys , err := plugin .bfdHandler .DumpBfdKeys ()
397
- if err != nil {
398
- return bfdAuthKeyList , err
399
- }
400
-
401
- for _ , key := range keys {
402
- // resolve authentication type
403
- var authType bfd.SingleHopBFD_Key_AuthenticationType
404
- if key .AuthType == 4 {
405
- authType = bfd .SingleHopBFD_Key_KEYED_SHA1
406
- } else {
407
- authType = bfd .SingleHopBFD_Key_METICULOUS_KEYED_SHA1
408
- }
409
-
410
- bfdAuthKeyList = append (bfdAuthKeyList , & bfd.SingleHopBFD_Key {
411
- Id : key .ConfKeyID ,
412
- AuthKeyIndex : key .ConfKeyID ,
413
- AuthenticationType : authType ,
414
- })
415
- }
416
-
417
- return bfdAuthKeyList , nil
418
- }
419
-
420
367
// ConfigureBfdEchoFunction is used to setup BFD Echo function on existing interface
421
368
func (plugin * BFDConfigurator ) ConfigureBfdEchoFunction (bfdInput * bfd.SingleHopBFD_EchoFunction ) error {
422
369
plugin .log .Infof ("Configuring BFD echo function for source interface %v" , bfdInput .EchoSourceInterface )
0 commit comments